Skip to content

problem accessing canvas on MacOS 10.11.6 with matplotlib 2.0.0b3 #6980

@lebedov

Description

@lebedov

When I try running the below code directly with python (or within IPython 5.1.0 after running %matplotlib qt4 with the matplotlib.use('Qt4Agg') line removed),

import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np

f = plt.gcf()
plt.imshow(np.random.rand(100, 100))
plt.draw()
im = np.fromstring(f.canvas.tostring_rgb(), dtype=np.uint8)

I observe the following error:

Traceback (most recent call last):
  File "test_renderer.py", line 9, in <module>
    im = np.fromstring(f.canvas.tostring_rgb(), dtype=np.uint8)
  File "/Users/lebedov/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 484, in tostring_rgb
    return self.renderer.tostring_rgb()
AttributeError: 'FigureCanvasQTAgg' object has no attribute 'renderer'

If I'm in IPython and run the script a second time after the above exception, no error occurs. Moreover, if I add f.canvas.draw() before I try to run f.canvas.tostring_rgb(), the error goes away. Also, the error appears to occur with backends other than qt4 such as tk (although not with agg).

Could this be related to #5058?

I'm running matplotlib 2.0.0b3 with Python 2.7.12 and PyQt4 4.11.4 (all installed in Anaconda from conda-forge) on MacOS 10.11.6.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions