Open mielune opened 1 year ago
I will try with
colors[i % len(colors)]
in both lines 733 and 775 to rotate on the colors if not enough available, without crash.
Hello, sorry I am a bit absent from solving issue recently, as I am (slowly) rebuilding the package from ground up.
Can I ask you to send the code you used to produce the error?
Thanks for reporting and your inputs
Hi,
A small example to reproduce this issue: with 19 items it work fine, but with 20 failed.
import plotext as plt
from random import random
nb_items = 20 # Work fine with 19
nb_data = 30
items = [f"a{x+1}" for x in range(nb_items)]
data = [[int(random() * 100) for y in range(nb_data)] for x in range(nb_items)]
labels = [f"l{y+1}" for y in range(nb_data)]
plt.simple_stacked_bar(labels, data, labels=items, title="Test")
plt.show()
Result:
Traceback (most recent call last):
File "/home/techlab/drill/drillqueries/test.py", line 12, in <module>
plt.simple_stacked_bar(labels, data, labels=items, title="Test")
File "/home/techlab/drill/drillqueries/.venv/lib/python3.11/site-packages/plotext/_core.py", line 208, in simple_stacked_bar
_glob.simple_stacked_bar(*args, width = width, marker = marker, colors = colors, title = title, labels = labels)
File "/home/techlab/drill/drillqueries/.venv/lib/python3.11/site-packages/plotext/_global.py", line 37, in simple_stacked_bar
bars = [ut.single_bar(x[i], Y[i], y[i], marker, colors[i]) for i in range(bars)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/techlab/drill/drillqueries/.venv/lib/python3.11/site-packages/plotext/_global.py", line 37, in <listcomp>
bars = [ut.single_bar(x[i], Y[i], y[i], marker, colors[i]) for i in range(bars)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/techlab/drill/drillqueries/.venv/lib/python3.11/site-packages/plotext/_utility.py", line 733, in single_bar
bar = [apply_ansi(bar[i], colors[i], 1) for i in range(l)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/techlab/drill/drillqueries/.venv/lib/python3.11/site-packages/plotext/_utility.py", line 733, in <listcomp>
bar = [apply_ansi(bar[i], colors[i], 1) for i in range(l)]
~~~~~~^^^
IndexError: list index out of range
I just created a PR with my fix: https://github.com/piccolomo/plotext/pull/192
Sorry if not in the process, I'm not used to work on Github.
Just to update and apologise: I have been quite busy rewriting the package from ground up and will update.
Hi,
I try to build a simple_stacked_bar with 22 stacked datasets but the lib crash on the colors Limit with 16 datasets is working but I need all of the 22.
Can I have a workaround ? It seems to be linked to the
colors[i]
out of range line 733 The ability to setup my own colors list ?With all datasets :
With only 16 datasets :
Kind regards,