Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
In the code below I tried to use pcolormesh to make a grid intensity plot. When thethe default option shading = 'flat' was written in the method, the code couldn't run. Either when I omitted writing this default configuration in the code or when I changed the code to shading = 'nearest', or other listed options in thedocumentation, the code worked smoothly. Note that the shape of x, y and z matched but the error was trying to say they didn't match.
Code for reproduction
importmatplotlob.pyplotaspltimportnumpyasnpx,y=np.meshgrid(np.arange(5),np.arange(3))z=x+yprint(np.shape(z))print(np.shape(x))print(np.shape(y))plt.pcolormesh(x,y,z,shading='flat')
Actual outcome
(3, 5)
(3, 5)
(3, 5)
TypeError Traceback (most recent call last)
Cell In [32], line 13
11 print(np.shape(x))
12 print(np.shape(y))
---> 13 plt.pcolormesh(x, y, z, shading = 'flat')
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/pyplot.py:2728, in pcolormesh(alpha, norm, cmap, vmin, vmax, shading, antialiased, data, *args, **kwargs)
2723 @_copy_docstring_and_deprecators(Axes.pcolormesh)
2724 def pcolormesh(
2725 *args, alpha=None, norm=None, cmap=None, vmin=None,
2726 vmax=None, shading=None, antialiased=False, data=None,
2727 **kwargs):
-> 2728 __ret = gca().pcolormesh(
2729 *args, alpha=alpha, norm=norm, cmap=cmap, vmin=vmin,
2730 vmax=vmax, shading=shading, antialiased=antialiased,
2731 **({"data": data} if data is not None else {}), **kwargs)
2732 sci(__ret)
2733 return __ret
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/init.py:1414, in _preprocess_data..inner(ax, data, *args, **kwargs)
1411 @functools.wraps(func)
1412 def inner(ax, *args, data=None, **kwargs):
1413 if data is None:
-> 1414 return func(ax, *map(sanitize_sequence, args), **kwargs)
1416 bound = new_sig.bind(ax, *args, **kwargs)
1417 auto_label = (bound.arguments.get(label_namer)
1418 or bound.kwargs.get(label_namer))
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axes/_axes.py:6064, in Axes.pcolormesh(self, alpha, norm, cmap, vmin, vmax, shading, antialiased, *args, **kwargs)
6061 shading = shading.lower()
6062 kwargs.setdefault('edgecolors', 'none')
-> 6064 X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
6065 shading=shading, kwargs=kwargs)
6066 coords = np.stack([X, Y], axis=-1)
6067 # convert to one dimensional array
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axes/_axes.py:5574, in Axes._pcolorargs(self, funcname, shading, *args, **kwargs)
5572 if shading == 'flat':
5573 if (Nx, Ny) != (ncols + 1, nrows + 1):
-> 5574 raise TypeError('Dimensions of C %s are incompatible with'
5575 ' X (%d) and/or Y (%d); see help(%s)' % (
5576 C.shape, Nx, Ny, funcname))
5577 else: # ['nearest', 'gouraud']:
5578 if (Nx, Ny) != (ncols, nrows):
TypeError: Dimensions of C (3, 5) are incompatible with X (5) and/or Y (3); see help(pcolormesh)
Expected outcome
No error
Additional information
I think the problem is in the section when shading = 'flat' in line 5574 in _axes.py as shown in the error message
Operating system
OS 12.4
Matplotlib Version
3.5.3
Matplotlib Backend
No response
Python version
No response
Jupyter version
6.4.12
Installation
pip