Skip to content

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

Merged
tacaswell merged 1 commit into
matplotlib:masterfrom
jklymak:fix-fallback-text-renderer
Sep 10, 2018
Merged

FIX: fallback text renderer to fig._cachedRenderer, if none found#12012
tacaswell merged 1 commit into
matplotlib:masterfrom
jklymak:fix-fallback-text-renderer

Conversation

@jklymak

@jklymak jklymak commented Sep 4, 2018

Copy link
Copy Markdown
Member

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

jklymak commented Sep 4, 2018

Copy link
Copy Markdown
Member Author

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

@anntzer

anntzer commented Sep 5, 2018

Copy link
Copy Markdown
Contributor

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