Skip to content

Matplotlib >= v3.3.3 breaks with pandas.plotting.register_matplotlib_converters(), ax.pcolormesh(), and datetime objects #19871

Description

@w2naf

Bug report

Bug summary

Matplotlib >= v3.3.3 breaks when using pandas.plotting.register_matplotlib_converters(), ax.pcolormesh(), and and array of datetime.datetime() objects as coordinates.

Code was tested using clean conda environments only differing by Matplotlib version. Versions tested:

  • mpl v3.3.2: Code works
  • mpl v3.3.3: Code breaks
  • mpl v3.4.1: Code breaks

Code for reproduction
The code below will work if the following lines are commented/removed:

from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
#!/usr/bin/env python3
from matplotlib import pyplot as plt
import numpy as np
import datetime

from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

fig = plt.figure()
ax  = fig.add_subplot(111)

times   = [datetime.datetime(2021,1,1)]
while len(times) < 721:
    times.append(times[-1]+datetime.timedelta(seconds=120))

y_vals  = np.arange(101)

time_axis, y_axis   = np.meshgrid(times,y_vals)
shape               = (len(y_vals)-1,len(times)-1)
z_data              = np.arange(shape[0]*shape[1])
z_data.shape        = shape

im = ax.pcolormesh(time_axis, y_axis, z_data)
fig.savefig('bug_report.png')

Actual outcome

This traceback comes from my Matplotlib 3.4.1 conda environment:

Traceback (most recent call last):
  File "./bug_report.py", line 23, in <module>
    im = ax.pcolormesh(time_axis, y_axis, z_data)
  File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/__init__.py", line 1352, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 6163, in pcolormesh
    shading=shading, kwargs=kwargs)
  File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5655, in _pcolorargs
    Nx = X.shape[-1]
AttributeError: 'list' object has no attribute 'shape'

This traceback comes from my Matplotlib 3.3.3 conda environment:

Traceback (most recent call last):
  File "./bug_report.py", line 23, in <module>
    im = ax.pcolormesh(time_axis, y_axis, z_data)
  File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1447, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 6093, in pcolormesh
    shading=shading, kwargs=kwargs)
  File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5590, in _pcolorargs
    Nx = X.shape[-1]
AttributeError: 'list' object has no attribute 'shape'

Expected outcome
Output from my Matplotlib 3.3.2 conda environment:
bug_report

Matplotlib version

  • Operating system: Ubuntu 18.04.5 LTS
  • Matplotlib version: Code breaks in v3.3.3 and v3.4.1; Code works in v3.3.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.7.7
  • Other libraries: Pandas v1.2.3

Matplotlib and python were installed with Anaconda for Linux 64 Bit. (conda 4.9.2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions