8000 FIX: internally Matplotlib works in screen pixels not logical pixels · matplotlib/matplotlib@a40620a · GitHub
[go: up one dir, main page]

Skip to content

Commit a40620a

Browse files
committed
FIX: internally Matplotlib works in screen pixels not logical pixels
1 parent 41bd991 commit a40620a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,20 @@ def leaveEvent(self, event):
261261
FigureCanvasBase.leave_notify_event(self, guiEvent=event)
262262

263263
def mouseEventCoords(self, pos):
264-
"""
265-
Calculate mouse coordinates in logical pixels.
264+
"""Calculate mouse coordinates in physical pixels
265+
266+
Qt5 use logical pixels, but the figure is scaled to physical
267+
pixels for rendering. Transform to physical pixels so that
268+
all of the down-stream transforms work as expected.
269+
270+
Also, the origin is different and needs to be corrected.
266271
267-
Qt5 and Matplotlib use logical pixels, but the figure is scaled to
268-
physical pixels for rendering. Also, the origin is different and needs
269-
to be corrected.
270272
"""
273+
dpi_ratio = self._dpi_ratio
271274
x = pos.x()
272275
# flip y so y=0 is bottom of canvas
273-
y = self.figure.bbox.height / self._dpi_ratio - pos.y()
274-
return x, y
276+
y = self.figure.bbox.height / dpi_ratio - pos.y()
277+
return x * dpi_ratio, y * dpi_ratio
275278

276279
def mousePressEvent(self, event):
277280
x, y = self.mouseEventCoords(event.pos())

0 commit comments

Comments
 (0)
0