Skip to content

FIX: fallback text renderer to fig._cachedRenderer, if none found #12012

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
Sep 10, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Sep 4, 2018

PR Summary

Closes #10874. See also #11004, and #10881. This is a more general backstop than the ticking fixes being proposed in #10874.

If a text obejct is created, but never drawn, its renderer never gets set (self._renderer). Subsequnet calls to self.get_window_extent() that do not specify the renderer fail with RuntimeError('Cannot get window extent w/o renderer').

Here I propose that we fall back on the cached renderer for the figure.

Test code:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, frameon=True)
ax.plot()
plt.get_current_fig_manager().canvas.draw()

for xtick in ax.get_xticklabels():
    bb = xtick.get_window_extent()

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak added this to the v2.2.4 milestone Sep 4, 2018
@jklymak
Copy link
Member Author

jklymak commented Sep 4, 2018

Milestoning for backporting, because this actually fixes a regression...

@anntzer
Copy link
Contributor

anntzer commented Sep 5, 2018

I guess this runs afoul of #11971 (comment), but OTOH I can't think of anything better right now.
Edit: it probably doesn't matter anyways (as in "we're already doing it wrong"), see comment on that thread.

@tacaswell tacaswell merged commit 10ffa53 into matplotlib:master Sep 10, 2018
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 10, 2018
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 10, 2018
QuLogic added a commit that referenced this pull request Sep 10, 2018
…012-on-v2.2.x

Backport PR #12012 on branch v2.2.x (FIX: fallback text renderer to fig._cachedRenderer, if none found)
QuLogic added a commit that referenced this pull request Sep 10, 2018
…012-on-v3.0.x

Backport PR #12012 on branch v3.0.x (FIX: fallback text renderer to fig._cachedRenderer, if none found)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError: Cannot get window extent w/o renderer
4 participants