Closed
Description
Bug report
Bug summary
Matplotlib 2.2.0 seems to introduce regression regarding the use of Agg
renderer. In specific cases, get_window_extent() does raise RuntimeError: Cannot get window extent w/o renderer
.
Code for reproduction
#!/usr/bin/env python3
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, frameon=True)
ax.plot()
# If the call to draw() below is removed, everything works
# However, this line cases xtick and ytick get_window_extent()
# to raise 'RuntimeError: Cannot get window extent w/o renderer'
# on matplotlib 2.2.0 (tested also on 2.2.2)
#
# Moreover, this works just fine with and without the call to
# draw() below, with matplotlib 2.1.2
plt.get_current_fig_manager().canvas.draw()
ax.set_xlabel(ax.get_xlabel()).get_window_extent()
ax.set_ylabel(ax.get_ylabel()).get_window_extent()
for xtick in ax.get_xticklabels():
xtick.get_window_extent()
for ytick in ax.get_yticklabels():
ytick.get_window_extent()
Actual outcome
Traceback (most recent call last):
File "matplotlib-bug.py", line 22, in <module>
xtick.get_window_extent()
File "/usr/lib/python3.6/site-packages/matplotlib/text.py", line 920, in get_window_extent
raise RuntimeError('Cannot get window extent w/o renderer')
RuntimeError: Cannot get window extent w/o renderer
Expected outcome
No exception should be raised. No exception is raised when the code is used with matplotlib 2.1.2.
Matplotlib version
- Operating system: Arch Linux
- Matplotlib version: 2.2.2
- Matplotlib backend (
print(matplotlib.get_backend())
): agg - Python version: 3.6.4
Installed with pacman -S python python-matplotlib
. Tested against older version of matplotlib by installing them in virtualenv using pip.
Metadata
Metadata
Assignees
Labels
No labels