question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support inset_axes zooms for all GeoAxes projections

See original GitHub issue

Description

inset_axes doesn’t work for geographic plots.

Steps to reproduce

import proplot as plot

f, axs = plot.subplots(
    ncols=2, axwidth=2.5,
    proj='robin', proj_kw={'lon_0': 180}
)
axs.format(
    suptitle='Figure with single projection',
    coast=True, latlines=30, lonlines=60
)

axi = axs.inset(
    [0, 0, 10, 10], transform='data', zoom=True,
    zoom_kw={'color': 'red3', 'lw': 2}
)

Error

Traceback (most recent call last):
  File "test_del.py", line 16, in <module>
    zoom_kw={'color': 'red3', 'lw': 2}
  File "/yin_raid/xin/miniconda3/envs/python37/lib/python3.7/site-packages/proplot/subplots.py", line 217, in _iterator
    ret.append(func(*args, **kwargs))
  File "/yin_raid/xin/miniconda3/envs/python37/lib/python3.7/site-packages/proplot/axes.py", line 1334, in inset_axes
    bb = locator(None, None)
  File "/yin_raid/xin/miniconda3/envs/python37/lib/python3.7/site-packages/proplot/axes.py", line 348, in inset_locator
    bb = mtransforms.TransformedBbox(bbox, trans)
  File "/yin_raid/xin/miniconda3/envs/python37/lib/python3.7/site-packages/matplotlib/transforms.py", line 1005, in __init__
    raise ValueError("'transform' must be an instance of "
ValueError: 'transform' must be an instance of 'matplotlib.transform.Transform'

Proplot version

0.5.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lukelbdcommented, Apr 22, 2020

This is actually not an advertised feature but it’s on my to-do list under the category “make XYAxes features work with rectangular projections like Mercator and Plate Carrée”. See #131 for details.

Will leave this issue open as a feature request for now. As a workaround you can probably make your own inset axes using the default cartopy API with e.g.

import cartopy.crs as ccrs
ax = fig.add_axes([x0, x1, y0, y1], projection=ccrs.PlateCarree())
ax.set_extent([lon0, lon1, lat0, lat1])
<plotting_code_here>
0reactions
lukelbdcommented, Jan 24, 2022

This seems to work pretty well for Plate Carree projections in the latest version. Have to set manually set the left/bottom spaces or else the result is wrong… but not too much effort.

import proplot as pplt
import cartopy.crs as ccrs
pplt.rc.reso = 'med'
fig, axs = pplt.subplots(
    proj='pcarree', coast=True, tight=True, bottom=7, left=1
)
fig.format(lonlim=(0, 180), latlim=(0, 90))
axs.scatter(120, 30)
bounds = (0.8, -0.6, 0.8, 0.8)
iax = axs.inset(bounds, proj='pcarree', zoom=True, zoom_kw={'ec': 'red', 'lw': 2})
iax.format(coast=True, rivers=True, lonlim=(100, 130), latlim=(15, 40))
fig.show()

tmp1

Non-Plate Carree are a different story thought. Again matplotlib isn’t supplying the correct bounds:

import proplot as pplt
import cartopy.crs as ccrs

pplt.rc.reso = 'med'
fig, axs = pplt.subplots(
    proj='robin', coast=True, tight=True, bottom=7, left=1
)
fig.format(lonlim=(0, 180), latlim=(0, 90))
axs.scatter(120, 30)
bounds = (0.8, -0.6, 0.8, 0.8)
iax = axs.inset(bounds, proj='pcarree', zoom=True, zoom_kw={'ec': 'red', 'lw': 2})
iax.format(coast=True, rivers=True, lonlim=(100, 130), latlim=(15, 40))

tmp2

Since the issue with using the wrong “transform” is fixed I’ll remove the “bug” tag.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble using Insetposition for Inset Axes with Cartopy
... #GeoAxes has a width/height ratio according to self's projection ... Do not support a interactive zoom in and out # so plz...
Read more >
Zoom region inset axes — Matplotlib 3.6.2 documentation
Example of an inset axes and a rectangle showing where the zoom is located. The use of the following functions, methods, classes and...
Read more >
correctly treat pan/zoom events of overlapping axes #22347
you'd need to ensure that the inset-axes has the same projection; you'd have to identify the clicked point in data-coordinates and adjust the...
Read more >
Axes — ProPlot documentation
Draw lines indicating the zoom range of the inset axes. ... Basically, any object with a get_cmap method, like the objects returned by...
Read more >
Cartopy matplotlib integration reference document - SciTools
Create a GeoAxes object using standard matplotlib Axes args and kwargs. Kwargs: map_projection - The target Projection of. this Axes object. All ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found