piccolomo / plotext

plotting on terminal
MIT License
1.77k stars 82 forks source link

plot not aligned when using marker=braille #213

Open fabiog1901 opened 2 months ago

fabiog1901 commented 2 months ago

When plotting a line chart using marker=braille, the rows are not aligned properly. In the terminal they are printed correctly, but not when saved to text or html file.

fabiog1901 commented 2 months ago

This is how to replicate the issue:

#!/usr/bin/python

import plotext as plt

index = [ 20,  30,  40,  50,  60,  70,  80,  90, 100, 110, 120, 130, 140,
       150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270,
       280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
       410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530,
       540, 550, 560, 570, 580, 590, 601]

p99 = [76.88,  60.14,  75.78,  61.77,  71.94, 74.34,  77.24, 76.91, 91.06, 77.19,
       76.38, 96.32, 70.77, 80.99, 75.74, 60.03, 77.74, 78.11, 80.44, 60.54,
       71.47 , 74.51, 77.67, 63.56, 96.81, 87.24 ,100.2,  99.72 ,121.81 ,121.24,
       100.39 ,100.43, 106.67 ,115.05, 125.45, 108.61, 120.43 ,102.87 ,131.27 ,104.08,
       124.23 ,103.53, 99.84 ,115.3, 106.29, 112.45, 102.66, 98.35, 104.33 ,100.98,
       102.85, 106.52, 100.49, 94.12, 122.33, 97.77 ,158.98 ,103.44, 94.07]

p50 = [54.19, 54.26, 54.15, 53.86, 54.05, 53.74, 54.06, 53.95, 54.46, 53.86, 54.3, 54.77,
       54.54, 54.02, 54.61, 54.2,  55.45, 55.55, 55.19, 55.84, 55.76, 55.69, 55.85, 55.61,
       56.03, 56.4,  66.92, 69.01, 69.22, 69.0,  69.15, 68.44, 69.14, 68.51, 68.27, 68.7,
       70.56, 68.76, 69.01, 69.68, 69.08, 68.77, 68.76, 68.55, 69.27, 68.87, 69.63, 69.96,
       68.37, 68.5, 69.39, 68.81, 68.41, 70.93, 69.87, 68.71, 68.9, 73.14, 68.97]

# braille
plt.clf()
plt.plot(index, p99, label="p99_ms", marker="braille")
plt.plot(index, p50, label="p50_ms", marker="braille")
plt.build()
plt.save_fig("plt-braille.txt", append=False, keep_colors=False)

# dot and hd
plt.clf()
plt.plot(index, p99, label="p99_ms", marker="dot")
plt.plot(index, p50, label="p50_ms", marker="hd")
plt.build()
plt.save_fig("plt-braille.txt", append=True, keep_colors=False)

and this is the output when opened with a text editor such as macos TextEdit or VSCode:

     ┌──────────────────────────────────────────────────┐
159.0┤ ⢕⢕ p99_ms                                     ⣾  │
     │ ⢕⢕ p50_ms                                     ⣿  │
141.4┤                                               ⣿  │
     │                                               ⣿  │
     │                             ⡀  ⣾ ⡀            ⡇⡇ │
123.9┤                       ⢠⢲   ⡸⡇⣠ ⣿⢸⡇          ⢠⡆⡇⡇ │
     │                       ⢸⠸⡀ ⢠⠃⢸⡿⣸⢸⡜⢱ ⡾⡀⣠      ⢸⡇⡇⡇ │
106.4┤                       ⡇ ⡇ ⡜  ⠁⢿⠸⡇⠸⡀⡇⠳⢹  ⡀⢀⠴⡀⡎⢸⡇⢇ │
     │         ⢀          ⢀⢠⠒⠃ ⠑⠚        ⠈⠃  ⠑⠎⠑⠁ ⢱⡇⠘⠇⠘⡄│
 88.8┤      ⢀⡄ ⣿          ⡟⣼                       ⠁   ⠈│
     │      ⡸⡇⢰⢹          ⡇⠈                            │
     │⡄⢀  ⢀⠤⠇⠣⠼⢸⡰⠣⡀⡠⠔⢺  ⣠⢰⠁                             │
 71.3┤⢇⡿⡀⡔⠁    ⠈⠃ ⢇⡇ ⢸⢠⠊⠘⣼  ⢀⠤⠤⠤⣀⡠⣀⣀⡠⣀⡠⠤⢄⣀⣀⡠⣀⠤⢄⣀⡠⣀⣠⠢⢄⣠⠊⠢│
     │⠸⡇⠻         ⠸⡇ ⠸⡎  ⠙ ⢰⠁                           │
 53.7┤⣀⣀⣀⣀⣀⣀⣀⣀⣀⡠⣀⣀⣀⡠⠤⠤⠤⠤⠤⠤⠤⠼                            │
     └┬───────────┬────────────┬───────────┬───────────┬┘
    20.0        165.2        310.5       455.8     601.0 
     ┌──────────────────────────────────────────────────┐
159.0┤ •• p99_ms                                     •  │
     │ ▞▞ p50_ms                                    ••  │
141.4┤                                              ••  │
     │                                              ••  │
     │                             •  •             ••  │
123.9┤                        •   ••••• •           ••  │
     │                       ••   ••••••• • •      •••  │
106.4┤                       ••  •  •• • • • •• •• •• • │
     │         •          • •• ••        •    ••  ••• • │
 88.8┤       •••         •••                       •   •│
     │      •••• •   •   • •                            │
     │• • ••• ••• ••••  ••                              │
 71.3┤••••      • •• • • •  ▄▄▄▄▄▄▄▄▞▄▄▄▄▄▄▄▄▄▄▄▄▄▄▚▄▄▞▄│
     │ • •         •  •  • ▐                            │
 53.7┤▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀▀▀▀                            │
     └┬───────────┬────────────┬───────────┬───────────┬┘
    20.0        165.2        310.5       455.8     601.0 
piccolomo commented 1 month ago

Just to update and apologise: I have been quite busy rewriting the package from ground up and will update.