Comments (4)
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 \u2800
- \u28FF
see wikipedia) and if colors are involved, each character is surrounded by quite some ANSI escape codes. Hence, we need to do some manual computation:
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)
from plotille.
Hmm, I see, I underestimated the hidden complexity of using unicode characters.
Does the Y-axis always take up 13 characters?
And on 'completely' unrelated topic, maybe precision here should be altered. I mean for the left plot only one digit after a dot will be sufficient.
But anyway, big thanks!
from plotille.
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.
Does the Y-axis always take up 13 characters?
Yes: 10 characters for the number formatting and 3 for the ' | '
at the end. See here: https://github.com/tammoippen/plotille/blob/master/plotille/_figure.py#L203
And on 'completely' unrelated topic, maybe precision here should be altered. I mean for the left plot only one digit after a dot will be sufficient.
Sounds good and should be not so difficult. I am open for PR 😄 Otherwise, it will probably take me some time.
from plotille.
closing.
from plotille.
Related Issues (20)
- Not getting the graph as required HOT 8
- Four quandrant scatter plot misalignment HOT 7
- Some ideas for optimization. HOT 4
- weird spike at zero HOT 4
- install failed: AttributeError: module 'enum' has no attribute 'IntFlag' HOT 1
- Accept `datetime.date` as X input HOT 6
- Draw vertical or horizontal lines on plots HOT 4
- [feature request] Provide a CLI HOT 3
- Make y-values exakt or approximate values of the data inputs HOT 5
- Histogram breaks when all values are the same HOT 1
- Index out of bounds for hist() on negative values HOT 3
- has someone ever integrated this on a curses-like interface ? HOT 4
- hex colors not showing up when parsing terminal results HOT 3
- `Figure.axvline(x) coordinates are wrong` HOT 2
- Windows 10 terminal does not display brailles HOT 2
- Log scale for plot() HOT 2
- [Feature request] support arrow HOT 2
- [Feature Request] Treemaps HOT 1
- Feature request: Network graph HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotille.