Skip to content
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

FigureCanvasQTAgg' object has no attribute '_update_dpi' #2

Open
knutaros opened this issue Feb 27, 2020 · 9 comments
Open

FigureCanvasQTAgg' object has no attribute '_update_dpi' #2

knutaros opened this issue Feb 27, 2020 · 9 comments

Comments

@knutaros
Copy link

Traceback (most recent call last):
File "/home/kklingbe/.local/lib/python2.7/site-packages/xmlplot-0.9.17-py2.7.egg/xmlplot/mpl_backend_qt4.py", line 43, in paintEvent
if self._update_dpi():
AttributeError: 'FigureCanvasQTAgg' object has no attribute '_update_dpi'

@jornbr
Copy link
Member

jornbr commented Feb 28, 2020

What version of matplotlib?

@knutaros
Copy link
Author

knutaros commented Feb 28, 2020 via email

@jornbr
Copy link
Member

jornbr commented Feb 28, 2020

Hi Knut,

I'm afraid the only solution at the moment is to update to the latest MatPlotLib 2.2. PyNcView/xmlplot inherit from, and adapt, the MPL Qt backend. Therefore they do not work with all (older) MatPlotLib versions…

Best,

Jorn

@knutaros
Copy link
Author

knutaros commented Mar 3, 2020 via email

@bolding
Copy link
Contributor

bolding commented Mar 3, 2020 via email

@knutaros
Copy link
Author

knutaros commented Mar 3, 2020 via email

@elmikh
Copy link

elmikh commented Apr 16, 2021

Hi Knut, Jorn, Karsten and everybody interested,

I just had the same error recently, and I have found out the solution.

For the latest versions of Matplotlib (in my case I use Matplotlib 3.4.1) for Xmlplot package in mpl_backend_qt4.py file in the line 44 it you should change

if self._update_dpi():
to
if self._update_figure_dpi():

then everything works smooth and fine.

Best,
Elena

@markusReinert
Copy link

Hi,

thanks, Elena, for finding the solution! I have been struggling with this for quite some time.

It seems to me that in matplotlib 3.3.4 (and – I assume – in earlier versions, too), the method is called _update_dpi, but in matplotlib 3.4.1 (and newer versions), it is called _update_figure_dpi. While the method _update_figure_dpi also exists in matplotlib 3.3, it has a different effect there and does not scale the figure to the window size.

We should not ignore this issue, because people will update their matplotlib at one point, and then they will run into this problem (this happened to me). So I'm wondering what the best way to fix it would be.

  1. An easy solution would be to just make the change proposed by Elena. This would only cause problems for users that have the updated version of xmlplot but an old version of matplotlib. PyNcView would still be usable for them, only the figure would be smaller. One could, of course, require matplotlib 3.4.0 or newer, but this might be too restrictive.

  2. Another solution would be to put the call to _update_dpi into a "try except" construction, but this is probably not a nice solution for a function that is called a lot. Also, this might cause problems if matplotlib changes again.

  3. A third solution would be to explicitly check the version of matplotlib, and then use _update_dpi if the version number is less than 3.4.0 and otherwise _update_figure_dpi. I think this could work the best, but it is not a nice coding style, because we will then carry around an artifact of an old matplotlib version.

I'd be interested to hear your thoughts on this, @jornbr !

Best regards,
Markus

@markusReinert
Copy link

It appears to me that this issue is solved with the newer versions of matplotlib. With matplotlib version 3.5, I have no problems with pyncview any more, and I did not need to do any of the proposed changes.

I suggest marking this issue as solved.

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

No branches or pull requests

5 participants