Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,16 @@ def leaveEvent(self, event):
FigureCanvasBase.leave_notify_event(self, guiEvent=event)

def mouseEventCoords(self, pos):
x = pos.x() * self._dpi_ratio
"""
Calculate mouse coordinates in logical pixels.

Qt5 and Matplotlib use logical pixels, but the figure is scaled to
physical pixels for rendering. Also, the origin is different and needs
to be corrected.
"""
x = pos.x()
# flip y so y=0 is bottom of canvas
y = self.figure.bbox.height - pos.y() * self._dpi_ratio
y = self.figure.bbox.height / self._dpi_ratio - pos.y()
return x, y

def mousePressEvent(self, event):
Expand Down