-
Notifications
You must be signed in to change notification settings - Fork 362
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
Problem when using pcolormesh with matplotlib 3.8 #2208
Comments
Hi @l4nc3l0t thanks for the report. Could you post a self-contained code example that reproduces the problem? I have been doing some testing against the Matplotlib development branch and the above traceback is not reproduced in the tests. So I think we would need to understand what about your example is not covered by this test: cartopy/lib/cartopy/tests/mpl/test_mpl_integration.py Lines 270 to 314 in c4858e4
|
Seems to be a problem with nan in the rows if I insert
|
I'm using the nightly build from https://matplotlib.org/stable/users/installing/index.html#installing-a-nightly-build That's right using the https://github.com/rcomer/cartopy/pcolormesh-rgba branch solves the issue |
Thanks for the clear example. I have rebased #2166 and added a row of nans to the |
Description
Problem with colorbar when using pcolormesh with matplotlib 3.8 everything work with 3.7.2 something to do with masked data
(Try to replace pcolormesh by pcolor but another problem ('Colorbar' object has no attribute '_boundaries')
Don't know if it's a Cartopy or Matplotlib problem...
Traceback
File ~/Documents/***/.env/lib/python3.11/site-packages/matplotlib/pyplot.py:2230, in colorbar(mappable, cax, ax, **kwargs)
2225 if mappable is None:
2226 raise RuntimeError('No mappable was found to use for colorbar '
2227 'creation. First define a mappable such as '
2228 'an image (with imshow) or a contour set ('
2229 'with contourf).')
-> 2230 ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
2231 return ret
File ~/Documents/***/.env/lib/python3.11/site-packages/matplotlib/figure.py:1295, in FigureBase.colorbar(self, mappable, cax, ax, use_gridspec, **kwargs)
1291 cax.grid(visible=False, which='both', axis='both')
1293 NON_COLORBAR_KEYS = [ # remove kws that cannot be passed to Colorbar
1294 'fraction', 'pad', 'shrink', 'aspect', 'anchor', 'panchor']
-> 1295 cb = cbar.Colorbar(cax, mappable, **{
1296 k: v for k, v in kwargs.items() if k not in NON_COLORBAR_KEYS})
1297 cax.figure.stale = True
1298 return cb
File ~/Documents/***/.env/lib/python3.11/site-packages/matplotlib/colorbar.py:395, in Colorbar.init(self, ax, mappable, cmap, norm, alpha, values, boundaries, orientation, ticklocation, extend, spacing, ticks, format, drawedges, extendfrac, extendrect, label, location)
392 self.ticklocation = ticklocation
394 self.set_label(label)
--> 395 self._reset_locator_formatter_scale()
397 if np.iterable(ticks):
398 self._locator = ticker.FixedLocator(ticks, nbins=len(ticks))
File ~/Documents/***/.env/lib/python3.11/site-packages/matplotlib/colorbar.py:1159, in Colorbar._reset_locator_formatter_scale(self)
1153 def _reset_locator_formatter_scale(self):
1154 """
1155 Reset the locator et al to defaults. Any user-hardcoded changes
1156 need to be re-entered if this gets called (either at init, or when
1157 the mappable normal gets changed: Colorbar.update_normal)
1158 """
-> 1159 self._process_values()
1160 self._locator = None
1161 self._minorlocator = None
File ~/Documents/***/.env/lib/python3.11/site-packages/matplotlib/colorbar.py:1087, in Colorbar._process_values(self)
1084 b = np.hstack((b, b[-1] + 1))
1086 # transform from 0-1 to vmin-vmax:
-> 1087 if self.mappable.get_array() is not None:
1088 self.mappable.autoscale_None()
1089 if not self.norm.scaled():
1090 # If we still aren't scaled after autoscaling, use 0, 1 as default
File ~/Documents/***/.env/lib/python3.11/site-packages/cartopy/mpl/geocollection.py:24, in GeoQuadMesh.get_array(self)
22 # If the input array has a mask, retrieve the associated data
23 if hasattr(self, '_wrapped_mask'):
---> 24 A[self._wrapped_mask] = self._wrapped_collection_fix.get_array()
25 return A
File /usr/lib/python3.11/contextlib.py:81, in ContextDecorator.call..inner(*args, **kwds)
78 @wraps(func)
79 def inner(*args, **kwds):
80 with self._recreate_cm():
---> 81 return func(*args, **kwds)
File ~/Documents/***/.env/lib/python3.11/site-packages/numpy/ma/core.py:3385, in MaskedArray.setitem(self, indx, value)
3383 _data[indx.data] = dval
3384 else:
-> 3385 _data[indx] = dval
3386 _mask[indx] = mval
3387 elif hasattr(indx, 'dtype') and (indx.dtype == MaskType):
Full environment definition
Operating system
Ubuntu 23.04
Cartopy version
0.21.1
Matplotlib version
3.8.0.dev1496+g2c45571872
The text was updated successfully, but these errors were encountered: