GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: boxplot errors when `x` and `tick_labels` are empty · Issue #32304 · matplotlib/matplotlib

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

New issue
Copy link
New issue
Copy link
Open
Open
[Bug]: boxplot errors when x and tick_labels are empty#32304
Copy link
Labels
topic: plotting methodstopic: ticks axis labels

Description

@carlosgmartin
carlosgmartin
opened on Sep 5, 2026
Issue body actions

Bug summary

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

Code for reproduction

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

Activity

  1. iccir commented on Sep 5, 2026

    @iccir
    iccir
    on Sep 5, 2026
    Contributor
    More actions

    The documentation for tick_labels is:

    Ticks are always placed at the box positions

    And for positions:

    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.

  2. iccir
    added
    topic: plotting methods
    topic: ticks axis labels
    on Sep 5, 2026
  3. rcomer commented on Sep 12, 2026

    @rcomer
    rcomer
    on Sep 12, 2026
    Member
    More actions

    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

    plt.boxplot([])
    plt.boxplot([], tick_labels=['foo'])
  4. rcomer
    added
    status: needs clarificationIssues that need more information to resolve.Issues that need more information to resolve.
    on Sep 12, 2026
  5. rcomer commented on Sep 12, 2026

    @rcomer
    rcomer
    on Sep 12, 2026
    Member
    More actions

    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.

  6. carlosgmartin commented on Sep 12, 2026

    @carlosgmartin
    carlosgmartin
    on Sep 12, 2026
    ContributorAuthor
    More actions

    @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.

    Reacted by Ruth Comer
  7. rcomer
    removed
    status: needs clarificationIssues that need more information to resolve.Issues that need more information to resolve.
    on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: plotting methodstopic: ticks axis labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.