Description
Report
Summary
I was trying to use networkx to draw some graphs but matplotlib fails. So I tested some actual matplotlib examples without including networkx related code and I reproduced the same error. I suspect it may be related to Qt but cannot be sure. The error states as:
AttributeError: 'QPixmap' object has no attribute 'setDevicePixelRatio'
Code for reproduction
I am using python 2.7. The code I used was:
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C,S = np.cos(X), np.sin(X)
plt.plot(X,C)
plt.plot(X,S)
plt.show()
but it already fails in this line:
plt.plot(X,C)
Expected outcome
Expected outcome is this picture:
Matplotlib version
- Operating System: Lubuntu, 14.04.5 LTS
- Matplotlib Version: 2.0.1
- Python Version: Python 2.7.6
Qmake:
qmake --version
QMake version 3.0
Using Qt version 5.2.1 in /usr/lib/x86_64-linux-gnu
System info:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
uname -a
Linux thesisvm 4.4.0-75-generic #96~14.04.1-Ubuntu SMP Thu Apr 20 11:06:30 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Matplotlib info:
matplotlib.version
'2.0.1'
matplotlib.file
'/usr/local/lib/python2.7/dist-packages/matplotlib/init.pyc'
I cannot reproduce all the commands I issued but can give an outline.
I issued these commands:
sudo apt-get build-dep python-matplotlib
sudo pip install matplotlib
Full error trace:
plt.plot(X,C)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3306, in plot
ax = gca()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 950, in gca
return gcf().gca(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 586, in gcf
return figure()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4agg.py", line 46, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4agg.py", line 54, in new_figure_manager_given_figure
return FigureManagerQT(canvas, num)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 488, in init
self.toolbar = self._get_toolbar(self.canvas, self.window)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 539, in _get_toolbar
toolbar = NavigationToolbar2QT(canvas, parent, False)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 585, in init
NavigationToolbar2.init(self, canvas)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2760, in init
self._init_toolbar()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 601, in _init_toolbar
a = self.addAction(self._icon(image_file + '.png'),
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 591, in _icon
pm.setDevicePixelRatio(self.canvas._dpi_ratio)
AttributeError: 'QPixmap' object has no attribute 'setDevicePixelRatio'