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

Skip to content

Backport PR #23174: Make sure SubFigure has _cachedRenderer #23184

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
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 @@ -2082,6 +2082,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 @@ -520,3 +520,23 @@ def test_contour_autolabel_beyond_powerlimits():
ax.clabel(cs)
# Currently, the exponent is missing, but that may be fixed in the future.
assert {text.get_text() for text in ax.texts} == {"0.25", "1.00", "4.00"}


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")