New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two plots side-by-side #38
Comments
Hello @xtotdam , Welcome to the realm of unicode and console escape sequences. We cannot simply calculate the line-length here, as each visible 'character' can consist of up to 3 byte (dots are import os, sys
import plotille
import numpy as np
x = np.linspace(0, 1, 100)
rows = 5
columns = 40
y = 2*x
plot1 = plotille.plot(x, y,
lc='red', height=rows, width=columns, X_label='x', Y_label='T',
x_min=0, x_max=1, y_min=np.min(y), y_max=np.max(y))
y = np.exp(-x)
plot2 = plotille.plot(x, y,
lc='green', height=rows, width=columns, X_label='t', Y_label='T',
x_min=0, x_max=1, y_min=np.min(y), y_max=np.max(y))
print(plot1)
print(plot2)
print()
lines = plot1.split(os.linesep)
# last line is actually visually longest
max_line = len(lines[-1])
# Arrow up
lines[0] += " " * (max_line - len(lines[0])) + "| "
# max value line
lines[1] += " " * (max_line - len(lines[1])) + "| "
# canvas
# y-axis takes up 13 characters
for row_idx in range(rows):
lines[2 + row_idx] += " " * (max_line - 13 - columns) + "| "
# x-axis
lines[-2] += " " * (max_line - len(lines[-2])) + "| "
lines[-1] += " " * (max_line - len(lines[-1])) + "| "
plot = (os.linesep).join(l1 + l2 for (l1, l2) in zip(lines, plot2.split(os.linesep)))
print(plot) |
Hmm, I see, I underestimated the hidden complexity of using unicode characters. |
I think the most impact here actually do have the ansi escape characters; unicode will be correctly identified as one character from python, but when i looked at the bytes, there were quite some more.
Yes: 10 characters for the number formatting and 3 for the
Sounds good and should be not so difficult. I am open for PR 😄 Otherwise, it will probably take me some time. |
closing. |
Hi! I found this package very useful, thank you!
There is one thing I actually try to figure out without any success.
How do I print two plots side-by-side, I mean like 🖼️ 🖼️
Here is my code, but I have no success in making all lines same length:(
and here is what I get
The text was updated successfully, but these errors were encountered: