Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad1dfe5

Browse files
committed
Make sure SubFigure has _cachedRenderer
1 parent d73ba9e commit ad1dfe5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,10 @@ def __init__(self, parent, subplotspec, *,
20562056
def dpi(self):
20572057
return self._parent.dpi
20582058

2059+
@property
2060+
def _cachedRenderer(self):
2061+
return self._parent._cachedRenderer
2062+
20592063
@dpi.setter
20602064
def dpi(self, value):
20612065
self._parent.dpi = value
@@ -2134,7 +2138,6 @@ def axes(self):
21342138

21352139
def draw(self, renderer):
21362140
# docstring inherited
2137-
self._cachedRenderer = renderer
21382141

21392142
# draw the figure bounding box, perhaps none for white figure
21402143
if not self.get_visible():

lib/matplotlib/tests/test_contour.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,23 @@ def test_all_algorithms():
585585
ax.contourf(x, y, z, algorithm=algorithm)
586586
ax.contour(x, y, z, algorithm=algorithm, colors='k')
587587
ax.set_title(algorithm)
588+
589+
590+
def test_subfigure_clabel():
591+
# Smoke test for gh#23173
592+
delta = 0.025
593+
x = np.arange(-3.0, 3.0, delta)
594+
y = np.arange(-2.0, 2.0, delta)
595+
X, Y = np.meshgrid(x, y)
596+
Z1 = np.exp(-(X**2) - Y**2)
597+
Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)
598+
Z = (Z1 - Z2) * 2
599+
600+
fig = plt.figure()
601+
figs = fig.subfigures(nrows=1, ncols=2)
602+
603+
for f in figs:
604+
ax = f.subplots()
605+
CS = ax.contour(X, Y, Z)
606+
ax.clabel(CS, inline=True, fontsize=10)
607+
ax.set_title("Simplest default with labels")

0 commit comments

Comments
 (0)