#32304·matplotlib

[Bug]: boxplot errors when `x` and `tick_labels` are empty

Author: carlosgmartinCreated Sep 5, 2026Updated Sep 12, 2026
Labelstopic: ticks axis labelstopic: plotting methods

Bug summary

boxplot errors when the arguments x and tick_labels are both empty.

Code for reproduction

python
from matplotlib import pyplot as plt

plt.boxplot([], tick_labels=[])

Actual outcome

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

Expected outcome

Drawing nothing, without crashing.

Additional information

The error is raised here.

This happens because _reshape_2D([], "X") is returning [[]], which has a len of 1 rather than 0.

Operating system

macOS Tahoe 26.5.2

Matplotlib Version

3.11.1

Matplotlib Backend

macosx

Python version

Python 3.14.6

Jupyter version

7.6.0

Installation

pip