pass projection argument to plt.subplot when faceting with cartopy transform
See original GitHub issueI have a data
3D DataArray with Time
, Latitude
and Longitude
coordinates.
I want to plot maps of this dataset, faceted by Time. The following code
import cartopy.crs as ccrs
proj = ccrs.PlateCarree()
data.plot(transform=proj, col='Time', col_wrap=3, robust=True)
fails with
ValueError: Axes should be an instance of GeoAxes, got <class 'matplotlib.axes._subplots.AxesSubplot'>
this is because to plot with a transform, the axes must be a GeoAxes, which is done with something like plt.subplot(111, projection=proj)
. The implicit subplotting done when faceting does not do that. To make the faceting works, I had to do
import cartopy.crs as ccrs
proj = ccrs.PlateCarree()
data.plot(transform=proj, col='Time', col_wrap=3, robust=True, subplot_kws={'projection':proj})
I propose that, when plot faceting is requested with a transform
kw, the content of that keyword should be passed to the subplot function as a projection
argument automatically by default. If a projection is provided explicitely like in the call above, use that one.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
How do I change matplotlib's subplot projection of an existing ...
crs. CRS projections. but I was wondering if there is a proper matplotlib method to change a subplot axis projection after it was...
Read more >pass projection argument to plt.subplot when faceting with ...
I have a data 3D DataArray with Time , Latitude and Longitude coordinates. I want to plot maps of this dataset, faceted by...
Read more >Understanding the transform and projection keywords - SciTools
The projection argument is used when creating plots and determines the projection of the resulting plot (i.e. what the plot looks like). The...
Read more >Plotting — xarray 0.9.6+dev240.g5a28b89 documentation
The easiest way to create faceted plots is to pass in row or col arguments to the xarray plotting methods/functions. This returns a...
Read more >plotting.rst.txt - Xarray
To plot :py:class:`Dataset` objects simply access the relevant DataArrays, ... the plot to an existing axis pass in the axis as a keyword...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, this is what I meant with xarray not being directly “cartopy aware”. The reason is that xarray intends to be a general library, and tries to avoid defining too many keyword arguments in order to avoid confusion. However, xarray passes along any kw argument you want to the underlying mpl plot function (https://github.com/pydata/xarray/blob/master/xarray/plot/plot.py#L379). You’ll have to catch it first, either from the
kwargs
dict or by adding your own to the signature (the latter being recommended only if necessary, for the reason I mentioned above)I think the second example shows this: http://xarray.pydata.org/en/stable/plotting.html#maps
Related: #3169