You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: boxplot errors when x and tick_labels are empty #32304
Traceback (most recent call last):
File "<string>", line 1, in <module>
from matplotlib import pyplot as plt; plt.boxplot([], tick_labels=[])
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File "/venv/lib/python3.14/site-packages/matplotlib/_api/deprecation.py", line 477, in wrapper
return func(*args, **kwargs)
File "/venv/lib/python3.14/site-packages/matplotlib/pyplot.py", line 3234, in boxplot
return gca().boxplot(
~~~~~~~~~~~~~^
x,
^^
...<28 lines>...
**({"data": data} if data is not None else {}),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/venv/lib/python3.14/site-packages/matplotlib/_api/deprecation.py", line 477, in wrapper
return func(*args, **kwargs)
File "/venv/lib/python3.14/site-packages/matplotlib/__init__.py", line 1528, in inner
return func(
ax,
*map(cbook.sanitize_sequence, args),
**{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})
File "/venv/lib/python3.14/site-packages/matplotlib/axes/_axes.py", line 4541, in boxplot
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
labels=tick_labels, autorange=autorange)
File "/venv/lib/python3.14/site-packages/matplotlib/cbook.py", line 1269, in boxplot_stats
raise ValueError("Dimensions of labels and X must be compatible")
ValueError: Dimensions of labels and X must be compatible
The positions of the boxes. The ticks and limits are
automatically set to match the positions. Defaults to range(1, N+1) where N is the number of boxes to be drawn.
So it's expected that tick_labels and positions will line up. This also fails, although with a different error message:
plt.boxplot([], positions=[])
# ValueError: List of boxplot statistics and `positions` values must have same the length
I'm not sure what the proper behavior or fix should be.
Hi @carlosgmartin, could you say something about your use case and how you came to be passing these both as empty lists? I can imagine a workflow where the dataset X has an unknown number of data points, and sometimes zero data points. However, intuitively that dataset would still have a label associated with it so I'm unclear how you get the empty list of labels. I note that these both work fine
Actually I guess it could happen if you are appending an unknown number of data sets to your list, and sometimes zero data sets. In that case the user code could simply not call boxplot when the list is empty. If there are no data sets then there is nothing to do. Unfortunately the case
plt.boxplot([])
is ambigous: it could be one empty data set, or it could be zero data sets. The current Matplotlib behaviour seems to assume it is one empty data set.
Activity
iccir commentedon Sep 5, 2026
The documentation for
tick_labelsis:And for
positions:So it's expected that
tick_labelsandpositionswill line up. This also fails, although with a different error message:I'm not sure what the proper behavior or fix should be.
rcomer commentedon Sep 12, 2026
Hi @carlosgmartin, could you say something about your use case and how you came to be passing these both as empty lists? I can imagine a workflow where the dataset
Xhas an unknown number of data points, and sometimes zero data points. However, intuitively that dataset would still have a label associated with it so I'm unclear how you get the empty list of labels. I note that these both work finercomer commentedon Sep 12, 2026
Actually I guess it could happen if you are appending an unknown number of data sets to your list, and sometimes zero data sets. In that case the user code could simply not call
boxplotwhen the list is empty. If there are no data sets then there is nothing to do. Unfortunately the caseis ambigous: it could be one empty data set, or it could be zero data sets. The current Matplotlib behaviour seems to assume it is one empty data set.
carlosgmartin commentedon Sep 12, 2026
@rcomer My use case is handling N datasets, where sometimes N = 0.
Skipping the call entirely when N = 0 is a workaround, but not user-friendly.