Git Product home page Git Product logo

Comments (4)

tammoippen avatar tammoippen commented on May 24, 2024

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)

2021-05-31 09_23_52-TOTEM ❐ 0 ● 1 fish

from plotille.

xtotdam avatar xtotdam commented on May 24, 2024

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.

tammoippen avatar tammoippen commented on May 24, 2024

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.

tammoippen avatar tammoippen commented on May 24, 2024

closing.

from plotille.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.