Four quandrant scatter plot misalignment
Closed this issue · 7 comments
Versions:
plotille 3.6
Python 3.6.4 :: Anaconda custom (64-bit)
Windows 10 Version 1809
Environment:
Jupyter Lab Version 0.35.3
When plotting many points axes separators tend to become misaligned. Below is an example running a provided example script. This looks like a fantastic tool, would appreciate any help. Thank you.
Hello @FinFighter ,
Thank you for using / trying plotille
. The lib was designed to be used in a terminal:
- color output uses ANSI (and extensions) escape sequences, which are interpreted by a terminal as colors. See this wiki article for details. Also it detects, if the script is run in a
tty
session - if not, the escape sequences are not printed. Output would look even more ugly :D (see below) - in the terminal all (most) characters are printed in a grid of equal size, even if the used font uses characters that are not equal width. In most monospace fonts I tested, the braille characters are still wider than the ASCII characters. The terminal forces the characters into the grid. (BTW: the 'whitespace' within the axis are not ordinary space (ASCII 20) characters, but braille characters with no dot set:
\u2800
. See _dots.py for details on the handling of each character.)
Since Jupyter notebooks do not have the terminal grid formatting in the output, the braille characters misalign the output with respect to the axis.
Please try the script in the terminal:
import plotille
import numpy as np
X = np.sort(np.random.normal(size=1000))
fig = plotille.Figure()
fig.width = 60
fig.height = 3
fig.height = 30
fig.set_x_limits(min_=-3, max_=3)
fig.set_y_limits(min_=-1, max_=1)
fig.color_mode = 'byte'
fig.plot([-0.5, 1], [-1, 1], lc=25, label='First line')
fig.scatter(X, np.sin(X), lc=100, label='sin')
fig.plot(X, (X+2)**2, lc=200, label='square')
print(fig.show(legend=True))
The output with color escape sequences printed (for fun :D). The �
character is the ASCII ESC
character (\x1b
ASCII 27):
(Y) ^
1 |
0.93333333 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⢠�[0m�[38;5;200m⠇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀�[38;5;100m⡠�[0m�[38;5;100m⠞�[0m�[38;5;100m⠉�[0m⠀⠀�[38;5;100m⠉�[0m�[38;5;100m⠑�[0m�[38;5;100m⢄�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
0.86666667 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⢸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;25m⡎�[0m�[38;5;100m⢠�[0m�[38;5;100m⠞�[0m�[38;5;100m⠁�[0m⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠲�[0m�[38;5;100m⡀�[0m⠀⠀⠀⠀⠀⠀⠀⠀
0.80000000 | ⠀�[38;5;200m⢇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀�[38;5;25m⢠�[0m�[38;5;100m⣳�[0m�[38;5;100m⠋�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠐�[0m�[38;5;100m⡀�[0m⠀⠀⠀⠀⠀⠀⠀
0.73333333 | ⠀�[38;5;200m⢸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⢠�[0m�[38;5;200m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⣾�[0m�[38;5;100m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠘�[0m�[38;5;100m⠂�[0m⠀⠀⠀⠀⠀⠀
0.66666667 | ⠀�[38;5;200m⠈�[0m�[38;5;200m⡆�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀�[38;5;100m⣰�[0m�[38;5;100m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠄�[0m⠀⠀⠀⠀⠀
0.60000000 | ⠀⠀�[38;5;200m⢇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀�[38;5;100m⢠�[0m�[38;5;100m⡏�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠨�[0m�[38;5;100m⠄�[0m⠀⠀⠀⠀
0.53333333 | ⠀⠀�[38;5;200m⢸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀�[38;5;100m⢠�[0m�[38;5;100m⢯�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠸�[0m⠀⠀⠀⠀
0.46666667 | ⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀�[38;5;100m⡞�[0m�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
0.40000000 | ⠀⠀⠀�[38;5;200m⢸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀�[38;5;100m⡼�[0m�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
0.33333333 | ⠀⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀�[38;5;100m⢰�[0m�[38;5;100m⠃�[0m�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠄�[0m⠀
0.26666667 | ⠀⠀⠀⠀�[38;5;200m⠸�[0m�[38;5;200m⡀�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⡸�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀�[38;5;100m⢀�[0m�[38;5;100m⡏�[0m�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠁�[0m⠀
0.20000000 | ⠀⠀⠀⠀⠀�[38;5;200m⢇�[0m⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;200m⢠�[0m�[38;5;200m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀�[38;5;100m⡼�[0m⠀�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠂�[0m
0.13333333 | ⠀⠀⠀⠀⠀�[38;5;200m⠈�[0m�[38;5;200m⢆�[0m⠀⠀⠀⠀⠀⠀�[38;5;200m⢀�[0m�[38;5;200m⠏�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇�[38;5;100m⢰�[0m�[38;5;100m⠁�[0m�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
0.06666667 | ⠀⠀⠀⠀⠀⠀�[38;5;200m⠈�[0m�[38;5;200m⢆�[0m⠀⠀⠀⠀�[38;5;200m⢠�[0m�[38;5;200m⠊�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⣇�[0m�[38;5;100m⠇�[0m⠀�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
0 | ⣀⣀⣀⣀⣀⣀⣀⣀�[38;5;200m⣳�[0m�[38;5;200m⣄�[0m�[38;5;200m⣀�[0m�[38;5;200m⣰�[0m�[38;5;200m⣃�[0m⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀�[38;5;100m⣟�[0m⣀�[38;5;25m⣠�[0m�[38;5;25m⣃�[0m⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀
-0.0666667 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢰�[0m�[38;5;100m⡇�[0m⠀�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.1333333 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢀�[0m�[38;5;100m⠇�[0m⡇�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.2000000 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⡜�[0m⠀⡇�[38;5;25m⡎�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.2666667 | ⠀�[38;5;100m⠁�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢸�[0m�[38;5;100m⠁�[0m⠀�[38;5;25m⣧�[0m�[38;5;25m⠃�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.3333333 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢠�[0m�[38;5;100m⠇�[0m⠀⠀�[38;5;25m⡏�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.4000000 | ⠀⠀�[38;5;100m⠠�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⡞�[0m⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⡇�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.4666667 | ⠀⠀⠀�[38;5;100m⠂�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⡼�[0m⠀⠀⠀�[38;5;25m⡎�[0m⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.5333333 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢰�[0m�[38;5;100m⠃�[0m⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.6000000 | ⠀⠀⠀⠀�[38;5;100m⠘�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢀�[0m�[38;5;100m⠏�[0m⠀⠀⠀�[38;5;25m⡎�[0m⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.6666667 | ⠀⠀⠀⠀⠀�[38;5;100m⠠�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢀�[0m�[38;5;100m⡎�[0m⠀⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.7333333 | ⠀⠀⠀⠀⠀⠀�[38;5;100m⠰�[0m�[38;5;100m⡀�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢀�[0m�[38;5;100m⡞�[0m⠀⠀⠀⠀�[38;5;25m⡎�[0m⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.8000000 | ⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠑�[0m�[38;5;100m⡀�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢀�[0m�[38;5;100m⡞�[0m⠀⠀⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.8666667 | ⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠱�[0m⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⢠�[0m�[38;5;100m⠞�[0m⠀⠀⠀⠀⠀�[38;5;25m⡎�[0m⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-0.9333333 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠆�[0m�[38;5;100m⡀�[0m⠀⠀⠀⠀⠀⠀�[38;5;100m⡴�[0m�[38;5;100m⠋�[0m⠀⠀⠀⠀⠀�[38;5;25m⢠�[0m�[38;5;25m⠃�[0m⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-1 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀�[38;5;100m⠐�[0m�[38;5;100m⠦�[0m�[38;5;100m⣀�[0m�[38;5;100m⣀�[0m�[38;5;100m⣠�[0m�[38;5;100m⠴�[0m�[38;5;100m⠊�[0m⠀⠀⠀⠀⠀⠀⠀�[38;5;25m⡎�[0m⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-----------|-|---------|---------|---------|---------|---------|---------|-> (X)
| -3 -2 -1 0 1 2 3
Legend:
-------
�[38;5;25m⠤⠤ First line�[0m
�[38;5;100m⠤⠤ sin�[0m
�[38;5;200m⠤⠤ square�[0m
If you want to plot in jupyter notebook, better use matplotlib
. The magic commands do provide for a much better experience there.
I appreciate the reply and clarification. I now understand it is an issue with where the characters are being printed, not a problem with the library itself. My intended use case was to print the charts to a text file for more informative algorithm performance reports. After running the provided code in the bash console I get the expected output. I'll modify my program to use the console instead of Jupiter Notebook. Thank you!
Great that it works for you! Have fun. Best, Tammo