8000 [Bug]: plt.clabel raises exception at very low DPI: `ValueError: 'codes' must be a 1D list or array with the same length of 'vertices'. Your vertices have shape (2, 2) but your codes have shape (1,)` · Issue #26971 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: plt.clabel raises exception at very low DPI: ValueError: 'codes' must be a 1D list or array with the same length of 'vertices'. Your vertices have shape (2, 2) but your codes have shape (1,) #26971
Closed
@lpsinger

Description

@lpsinger

Bug summary

This worked up to and including Matplotlib 3.7.3 and broke in Matplotlib 3.8.0.

Data files for sample code below:
x.txt
y.txt
z.txt

Code for reproduction

import matplotlib
matplotlib.rcParams['figure.dpi'] = matplotlib.rcParams['savefig.dpi'] = 4

from matplotlib import pyplot as plt
import numpy as np

# See data files attached above: x.txt, y.txt, z.txt
x = np.loadtxt('x.txt')
y = np.loadtxt('y.txt')
z = np.loadtxt('z.txt')

ax = plt.axes()
contourset = ax.contour(x, y, z, levels=[90.0], linewidths=0.5)
ax.clabel(contourset)
plt.savefig('test.pdf')

Actual outcome

Traceback (most recent call last):
  File "/private/tmp/test.py", line 13, in <module>
    ax.clabel(contourset)
  File "/Users/lpsinger/Library/Python/3.11/lib/python/site-packages/matplotlib/axes/_axes.py", line 6550, in clabel
    return CS.clabel(levels, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lpsinger/Library/Python/3.11/lib/python/site-packages/matplotlib/contour.py", line 222, in clabel
    self.labels(inline, inline_spacing)
  File "/Users/lpsinger/Library/Python/3.11/lib/python/site-packages/matplotlib/contour.py", line 622, in labels
    rotation, path = self._split_path_and_get_label_rotation(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lpsinger/Library/Python/3.11/lib/python/site-packages/matplotlib/contour.py", line 436, in _split_path_and_get_label_rotation
    return angle, Path(xys, codes)
                  ^^^^^^^^^^^^^^^^
  File "/Users/lpsinger/Library/Python/3.11/lib/python/site-packages/matplotlib/path.py", line 135, in __init__
    raise ValueError("'codes' must be a 1D list or array with the "
ValueError: 'codes' must be a 1D list or array with the same length of 'vertices'. Your vertices have shape (2, 2) but your codes have shape (1,)

Expected outcome

test.pdf

Additional information

I discovered this regression in the CI pipeline from one of my own projects, in a test that sets DPI to an extremely low value for performance purposes. https://git.ligo.org/lscsoft/ligo.skymap/-/jobs/2961694

Operating system

macOS

Matplotlib Version

3.8.0

Matplotlib Backend

MacOSX

Python version

3.11.5

Jupyter version

N/A

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0