Skip to content

'QPixmap' object has no attribute 'setDevicePixelRatio' #8562

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

Closed
ederollora opened this issue May 3, 2017 · 5 comments
Closed

'QPixmap' object has no attribute 'setDevicePixelRatio' #8562

ederollora opened this issue May 3, 2017 · 5 comments

Comments

@ederollora
Copy link

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:

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'

@ederollora
Copy link
Author

I made it work after installing many packages but I doubt any of them had a real effect on it.
I switch the backend first to 'aag' (and it showed no error) and then when .show() did not work with 'aag' I switched to 'TKagg' and it worked.

import matplotlib.pyplot as plt
plt.switch_backend('TKagg')

This issue may be related to: #3466

@jenshnielsen
Copy link
Member

This is most likely a duplicate of the issue fixed and reported in #8559 It will affect qt4 and old version of qt5

@jenshnielsen
Copy link
Member

The agg backend is non interactive so it will never show anything

@ederollora
Copy link
Author

Thanks for the follow up. I actually installed from sources both PyQt4+SIP (and even PySide) and PyQt5.
If I specify the use of PyQt5 right after importing matplotlib:

import matplotlib
matplotlib.use('Qt5Agg')

Then it works but Qt4Agg and PySide still reproduce the error stated before. Hope this helps other people.

@ederollora
Copy link
Author

But I saw there was a fix for it, good to see :)

@QuLogic QuLogic added this to the 2.0.2 (next bug fix release) milestone May 3, 2017
@tacaswell tacaswell modified the milestones: 2.0.3 (next bug fix release), 2.0.2 (critical bug fixes from 2.0.1) May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants