|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +import matplotlib as mpl |
1 | 4 | import matplotlib.pyplot as plt |
| 5 | +from matplotlib.projections import PolarAxes |
2 | 6 | from matplotlib.testing.decorators import image_comparison |
| 7 | +from matplotlib.transforms import Affine2D |
3 | 8 |
|
4 | | -from mpl_toolkits.axisartist import AxisArtistHelperRectlinear |
| 9 | +from mpl_toolkits.axisartist import (AxisArtistHelperRectlinear, GridHelperCurveLinear, |
| 10 | + HostAxes) |
5 | 11 | from mpl_toolkits.axisartist.axis_artist import (AxisArtist, AxisLabel, |
6 | 12 | LabelBase, Ticks, TickLabels) |
7 | 13 |
|
@@ -90,3 +96,24 @@ def test_axis_artist(): |
90 | 96 | axisline.label.set_pad(5) |
91 | 97 |
|
92 | 98 | ax.set_ylabel("Test") |
| 99 | + |
| 100 | + |
| 101 | +@mpl.style.context('default') |
| 102 | +def test_axisartist_tightbbox(): |
| 103 | + fig = plt.figure() |
| 104 | + tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() |
| 105 | + grid_helper = GridHelperCurveLinear(tr) |
| 106 | + ax = fig.add_subplot(axes_class=HostAxes, grid_helper=grid_helper) |
| 107 | + ax.axis["lon"] = ax.new_floating_axis(1, 9) |
| 108 | + |
| 109 | + ax.set_xlim(-5, 12) |
| 110 | + ax.set_ylim(-5, 10) |
| 111 | + |
| 112 | + ax.axis['lon'].major_ticklabels.set_visible(False) |
| 113 | + |
| 114 | + # Since the labels are invisible and the lines are clipped to the axes, |
| 115 | + # the axis's tight bbox should be contained in the axes box. |
| 116 | + renderer = fig._get_renderer() |
| 117 | + tight_points = ax.axis['lon'].get_tightbbox(renderer).get_points() |
| 118 | + for point in tight_points: |
| 119 | + assert ax.bbox.contains(*point) |
0 commit comments