You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have embedded matplotlib in PyQt5 and I am using Ctrl+C to copy the figure to clipboard (for pasting to ppt)
So in the minimum example attached, pressing Ctrl+C reduces figure size to specified size (6x4). This is kind of a print preview for me. So I adjust legend/annotations in the smaller figure.
Dragging legend is not working properly in the smaller figure. It used to work in older versions for me. So I went through the changes. Reverting the change done in the following line of blit function of /backends/backend_qt.py fixes the problem (Changed as part of #17478)
This seems to occur because when a figure has no attached manager (as in the case of full embedding, which you use), its size (figsize/renderer size) can become different from the FigureCanvas widget size (because set_size_inches can't adjust it; indeed I can imagine cases of fixed GUI layout where this is impossible to do). Short of forbidding calls to set_size_inches in this case (you seem to have a reasonable, though perhaps slightly unusual, use case), I guess we just need to avoid assuming that these two sizes are equal, and your proposed patch indeed seems reasonable; one important point, though, is that renderer.height is not part of the guaranteed renderer API, so the correct expression is, I believe, something like self.repaint(l, int(self.figure.get_figheight() * self.figure.dpi / self.device_pixel_ratio) - t, w, h).
Confirming that self.repaint(l, int(self.figure.get_figheight() * self.figure.dpi / self.device_pixel_ratio) - t, w, h) is working. For now I will monkey patch blit function in my program.
Bug summary
This may not be a bug. It is my use case.
I have embedded matplotlib in PyQt5 and I am using
Ctrl+C
to copy the figure to clipboard (for pasting to ppt)So in the minimum example attached, pressing
Ctrl+C
reduces figure size to specified size (6x4). This is kind of a print preview for me. So I adjust legend/annotations in the smaller figure.Dragging legend is not working properly in the smaller figure. It used to work in older versions for me. So I went through the changes. Reverting the change done in the following line of
blit
function of/backends/backend_qt.py
fixes the problem (Changed as part of #17478)self.repaint(l, self.rect().height() - t, w, h)
to
self.repaint(l, int(self.renderer.height / self.device_pixel_ratio)- t, w, h)
For the normal figure
self.rect().height()
is equal toint(self.renderer.height / self.device_pixel_ratio)
But for the smaller figure
self.rect().height()
is different fromint(self.renderer.height / self.device_pixel_ratio)
Is this ok?
Thanks
Code for reproduction
Actual outcome
Expected outcome
Additional information
No response
Operating system
Windows
Matplotlib Version
3.6.2
Matplotlib Backend
PyQt5
Python version
3.8.10
Jupyter version
NA
Installation
pip
The text was updated successfully, but these errors were encountered: