Zoom into specific region of cartopy projection
See original GitHub issueI’m getting an error with proplot
when trying to zoom in to a specific subregion of my cartopy projection. I just want to map the California coastline, but it seems to break due to changes in the axis width. However, this works just fine with matplotlib
.
Any tips here? Should I be using something other than set_extent
that I can call in plot.subplots()
? Any thoughts on maintaining the right width/aspect for a zoomed in cartopy subplot? I’ve had trouble in the past with matplotlib
to get differing coastal regions to have the same width/height aspect ratio due to being in different latitudes.
proplot
f, ax = plot.subplots(width='12cm', proj='cyl')
ax.set_extent([-140, -107, 20, 50], crs=ccrs.PlateCarree())
Huge error chain ending in:
ValueError: Not enough room for axes (would have width -33.5696). Increase width, or reduce spacings 'left', 'right', or 'wspace'.
matplotlib
f, ax = plt.subplots(subplot_kw=dict(projection=ccrs.PlateCarree()))
ax.set_extent([-140, -107, 20, 50])
ax.coastlines()
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
cartopy: zoom in to a region - Stack Overflow
I would like to use Cartopy to plot only a region (in my case, ... longitude and latitude and line width ax =...
Read more >Zoom into specific region of cartopy projection #14 - GitHub
I'm getting an error with proplot when trying to zoom in to a specific subregion of my cartopy projection. I just want to...
Read more >Geographic and polar axes — ProPlot documentation
To zoom into cartopy projections, use set_extent or pass lonlim , latlim , or boundinglat to format . The boundinglat keyword controls the...
Read more >More advanced mapping with cartopy and matplotlib - SciTools
From the outset, cartopy's purpose has been to simplify and improve the quality of mapping visualisations available for scientific data.
Read more >Maps with Cartopy - Research Computing in Earth Sciences
Most classes of projection can be configured in projection-specific ways, although Cartopy takes an opinionated stance on sensible defaults.
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
P.S. In a recent commit (e78c43d), I fixed the issues with “smart tight layout” and zoomed-in cartopy projections. There is actually a cartopy github issue with the solution posted, it just hasn’t been implemented yet. ProPlot will now also fix issues associated with “zoomed in” cartopy projections having different aspect ratios than the intial aspect ratios, so you will no longer end up with a bunch of unnecessary empty space in your plot.
Anyway, now the only case when “smart tight layout” has to be disabled is when you use parallel/meridian labels with cartopy.
Thanks for all the tips, @lukelbd. I thought I had tried the
proj_kw
but maybe not. This is a pretty simple solution!Good example you added to the docs. Maybe you should also add one to polar-specific projections. I’m just getting into Southern Ocean stuff so getting used to these keywords. Note that of course it doesn’t use rectangular coordinates. You just pass
boundinglat
to set the extent.