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

Skip to content

Make sure SubFigure has _cachedRenderer #23174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,14 @@ def dpi(self):
def dpi(self, value):
self._parent.dpi = value

@property
def _cachedRenderer(self):
return self._parent._cachedRenderer

@_cachedRenderer.setter
def _cachedRenderer(self, renderer):
self._parent._cachedRenderer = renderer

def _redo_transform_rel_fig(self, bbox=None):
"""
Make the transSubfigure bbox relative to Figure transform.
Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,23 @@ def test_all_algorithms():
ax.contourf(x, y, z, algorithm=algorithm)
ax.contour(x, y, z, algorithm=algorithm, colors='k')
ax.set_title(algorithm)


def test_subfigure_clabel():
# Smoke test for gh#23173
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-(X**2) - Y**2)
Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)
Z = (Z1 - Z2) * 2

fig = plt.figure()
figs = fig.subfigures(nrows=1, ncols=2)

for f in figs:
ax = f.subplots()
CS = ax.contour(X, Y, Z)
ax.clabel(CS, inline=True, fontsize=10)
ax.set_title("Simplest default with labels")