|
4 | 4 |
|
5 | 5 | import matplotlib.colors as mcolors |
6 | 6 | import matplotlib.pyplot as plt |
| 7 | +import matplotlib.transforms as mtransforms |
7 | 8 | from matplotlib.testing.decorators import image_comparison, check_figures_equal |
8 | 9 |
|
9 | 10 |
|
@@ -104,3 +105,38 @@ def test_zoom_inset_connector_styles(): |
104 | 105 | # Make one visible connector a different style |
105 | 106 | indicator.connectors[1].set_linestyle('dashed') |
106 | 107 | indicator.connectors[1].set_color('blue') |
| 108 | + |
| 109 | + |
| 110 | +@image_comparison(['zoom_inset_transform.png'], remove_text=True, style='mpl20', |
| 111 | + tol=0.01) |
| 112 | +def test_zoom_inset_transform(): |
| 113 | + fig, ax = plt.subplots() |
| 114 | + |
| 115 | + ax_ins = ax.inset_axes([0.2, 0.2, 0.3, 0.15]) |
| 116 | + ax_ins.set_ylim([0.3, 0.6]) |
| 117 | + ax_ins.set_xlim([0.5, 0.9]) |
| 118 | + |
| 119 | + tr = mtransforms.Affine2D().rotate_deg(30) |
| 120 | + indicator = ax.indicate_inset_zoom(ax_ins, transform=tr + ax.transData) |
| 121 | + for conn in indicator.connectors: |
| 122 | + conn.set_visible(True) |
| 123 | + |
| 124 | + |
| 125 | +def test_zoom_inset_external_transform(): |
| 126 | + # Smoke test that an external transform that requires an axes (i.e. |
| 127 | + # Cartopy) will work. |
| 128 | + class FussyDataTr: |
| 129 | + def _as_mpl_transform(self, axes=None): |
| 130 | + if axes is None: |
| 131 | + raise ValueError("I am a fussy transform that requires an axes") |
| 132 | + return axes.transData |
| 133 | + |
| 134 | + fig, ax = plt.subplots() |
| 135 | + |
| 136 | + ax_ins = ax.inset_axes([0.2, 0.2, 0.3, 0.15]) |
| 137 | + ax_ins.set_xlim([0.7, 0.8]) |
| 138 | + ax_ins.set_ylim([0.7, 0.8]) |
| 139 | + |
| 140 | + ax.indicate_inset_zoom(ax_ins, transform=FussyDataTr()) |
| 141 | + |
| 142 | + fig.draw_without_rendering() |
0 commit comments