Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible dimensions with pcolormesh when using 'nearest' shading #1889

Closed
agijsberts opened this issue Sep 23, 2021 · 0 comments · Fixed by #1892
Closed

Incompatible dimensions with pcolormesh when using 'nearest' shading #1889

agijsberts opened this issue Sep 23, 2021 · 0 comments · Fixed by #1892
Assignees
Milestone

Comments

@agijsberts
Copy link

Description

Pull request #1646 made large changes to how pcolormesh interpolates its arguments. The new code appears to recalculate the edges when shading is nearest, thus adding an element to both x and y dimensions. But in the process it does not update the shading argument accordingly, causing MPL to complain about incompatible dimensions.

Code to reproduce

A minimal example demonstrating the exception is

import numpy as np
from matplotlib import pyplot as plt
import cartopy.crs as ccrs

ax = plt.axes(projection=ccrs.PlateCarree())

n=3
x = np.arange(n)+1
y = np.arange(n)+1
d = np.random.rand(n,n)

im = ax.pcolormesh(x, y, d, shading='nearest')

Traceback

The traceback when running the code

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    im = ax.pcolormesh(x, y, d, shading='nearest')
  File "/home/ec2-user/miniconda3/envs/arpav/lib/python3.8/site-packages/cartopy/mpl/geoaxes.py", line 318, in wrapper
    return func(self, *args, **kwargs)
  File "/home/ec2-user/miniconda3/envs/arpav/lib/python3.8/site-packages/cartopy/mpl/geoaxes.py", line 1797, in pcolormesh
    result = matplotlib.axes.Axes.pcolormesh(self, *args, **kwargs)
  File "/home/ec2-user/miniconda3/envs/arpav/lib/python3.8/site-packages/matplotlib/__init__.py", line 1361, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/ec2-user/miniconda3/envs/arpav/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 6183, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File "/home/ec2-user/miniconda3/envs/arpav/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5711, in _pcolorargs
    raise TypeError('Dimensions of C %s are incompatible with'
TypeError: Dimensions of C (3, 3) are incompatible with X (4) and/or Y (4); see help(pcolormesh)

Environment

Conda environment on Amazon Linux with cartopy 0.20.0 from conda-forge and matplotlib-base 3.4.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants