Skip to content

Commit da1f383

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31628: FIX: use axis lines tight bbox within axis artist tight bbox
1 parent 0f29072 commit da1f383

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def get_tightbbox(self, renderer=None):
10861086
*self.minor_ticklabels.get_window_extents(renderer),
10871087
self.label.get_window_extent(renderer),
10881088
self.offsetText.get_window_extent(renderer),
1089-
self.line.get_window_extent(renderer),
1089+
self.line.get_tightbbox(renderer),
10901090
]
10911091
bb = [b for b in bb if b and (b.width != 0 or b.height != 0)]
10921092
if bb:

lib/mpl_toolkits/axisartist/tests/test_axis_artist.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import numpy as np
2+
3+
import matplotlib as mpl
14
import matplotlib.pyplot as plt
5+
from matplotlib.projections import PolarAxes
26
from matplotlib.testing.decorators import image_comparison
7+
from matplotlib.transforms import Affine2D
38

4-
from mpl_toolkits.axisartist import AxisArtistHelperRectlinear
9+
from mpl_toolkits.axisartist import (AxisArtistHelperRectlinear, GridHelperCurveLinear,
10+
HostAxes)
511
from mpl_toolkits.axisartist.axis_artist import (AxisArtist, AxisLabel,
612
LabelBase, Ticks, TickLabels)
713

@@ -90,3 +96,24 @@ def test_axis_artist():
9096
axisline.label.set_pad(5)
9197

9298
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

Comments
 (0)