This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hello! Thanks for reaching out, and thanks for the helpful information. Unfortunately, with my own sample global GFS data, I'm unable to recreate this error in an environment identical to yours and in a similar, newer environment, across multiple machines. A sample of the data you're plotting might be helpful for me to faithfully recreate your code, but I've matched it fully as I'm able. Either way, I might have a few suggestions to try: First, I'd save a snippet of your data after processing. Then, with a new, bare minimum conda-only (no pip!) environment with *only* cartopy+matplotlib and whatever you need to open your data snippet, give this another try. Your error seems to indicate that your environment is not polluted by incorrectly linked libraries, pip installations, etc., but this could still be the case. If you've done something like install cartopy/shapely via pip, then update with conda, this could be an issue. Let me know the results of this! Another option might be to delete your cached cartopy features and re-download them if possible. By default, they are located at "$HOME/.local/share/cartopy/shapefiles". NOTE that you'll need a freshly installed cartopy>=0.19.0.post1 to re-download any NaturalEarth features due to some fixed URL issues. I'm not sure that this will help, but it might be worth a try. Don't hesitate to follow up and let me know the results of these. Failing these, the next best suggestion I have is to open an issue with the fine experts on the Cartopy or Shapely projects on GitHub, and see if any of them can dissect this better. Be sure to provide them with sample data and a fully-reproducible code snippet. Your environment specification is also very appreciated! https://github.com/SciTools/cartopy/issues/new (start here, they may point you to Shapely!) https://github.com/Toblerity/Shapely/issues/new Thanks again for your time and patience. I hope we can find a clearer answer! All the best, Drew > I am using Python 3.8 and using cartopy to make some plots. However, I am > consistently getting an error message when the map is ready to be drawn > (either to a window or to a figure for saving). The error occurs on either my > Linux machine (running CentOS 6.10) or my Mac (running OSX 10.15.7). Both use > a python 3.8 environment. > > I have attached details of the error, including sample code used to make the > plot. If you could please help with these errors, that would be appreciated. > This has been an ongoing issue for months and I cannot resolve it. I have > tried downgrading cartopy to earlier versions and then upgrading but with no > change. I also created a brand new python 3.8 environment and installed > cartopy (along with other packages like numpy, scipy, matplotlib, and > netCDF4) with again the same errors. > > Here is some sample code: > import os,sys,cartopy,warnings > import numpy as np > import cartopy.crs as ccrs > import matplotlib.pyplot as plt > from cartopy.util import add_cyclic_point > > # Load data, perform calculations... > # ..... > # ..... > # ..... > > > # Make map of results > cmin = -0.5; cmax = 0.51; cint = 0.05 > clevs = np.round(np.arange(cmin,cmax,cint),2) > nlevs = len(clevs) - 1 > > cmap = plt.get_cmap(name='RdBu_r',lut=nlevs) > > states_provinces = cartopy.feature.NaturalEarthFeature( > category='cultural', > name='admin_1_states_provinces_lines', > scale='50m', > facecolor='none') > > projection = ccrs.Miller(central_longitude=-180.) > data_crs = ccrs.PlateCarree() > extent = [-270,-30,20,80] # Set the map extents > > plot_data,plot_lon = add_cyclic_point(data,coord=lon,axis=0) > lat,lon = np.meshgrid(lat,plot_lon) > > plt.figure() > ax = plt.subplot(111,projection=projection) > ax.set_extent(extent,crs=data_crs) > ax.add_feature(cartopy.feature.BORDERS,edgecolor='gray',linewidth=1) > ax.add_feature(states_provinces,edgecolor='gray',linewidth=1) > ax.add_feature(cartopy.feature.LAKES,facecolor='white',edgecolor='gray',linewidth=1) > ax.coastlines(resolution='50m',color='black',linewidth=1) > cs=ax.contourf(lon,lat,plot_data,clevs,cmap=cmap,transform=data_crs) > > cbar=plt.colorbar(cs,orientation='horizontal') > > cticks = [] > for i in clevs: > cticks.append(int(i)) if i.is_integer() else cticks.append(i) > > cbar.set_ticks(clevs[::2]) > cbar.set_ticklabels(cticks[::2]) > > for i in cbar.ax.yaxis.get_ticklabels(): > i.set_size(14) > > plt.title('Test Plot',size=16) > > # plt.show(block=False) > plt.savefig('Test.png',dpi=400) > > > > Here is the error message: > > AttributeError: '_Shape' object has no attribute 'get' > Ticket Details =================== Ticket ID: LBW-397273 Department: Support Python Priority: Low Status: Closed =================== NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.