Fix occasional misalignment in reported mouse position (also fixes a bug with canvas height)#32038
Fix occasional misalignment in reported mouse position (also fixes a bug with canvas height)#32038ayshih wants to merge 3 commits into
Conversation
|
I’m wondering whether we should make an explicit concept out of this. While figure size can be any float, the canvas - at least for raster backends - must be integer. So it seems we should rather take the size from the canvas? Possibly https://matplotlib.org/stable/api/backend_bases_api.html#matplotlib.backend_bases.FigureCanvasBase.get_width_height |
6392c2b to
f7eb4c0
Compare
|
Per @timhoffm's suggestion, I changed the approach of this PR: I have fixed |
f7eb4c0 to
a594bbf
Compare
a594bbf to
4be3326
Compare
| backend. | ||
| """ | ||
| return tuple(int(size / (1 if physical else self.device_pixel_ratio)) | ||
| # Due to floating-point precision, round up width or height if either is very |
There was a problem hiding this comment.
It’s possibly a good idea to add to the docstring that rounding is used.
There was a problem hiding this comment.
I've added a note in the docstring
|
Given how this has changed, I guess I should point out #8265 and ask whether it is something that correlates with this PR. |
6ca1962 to
be67e7e
Compare
PR summary
Due to floating-point precision, a figure may self-report a height that is slightly below an integer (by one floating-point tick). When this happens, there are (at least) two bugs:
This PR:
FigureCanvasBase.get_width_height()so that it accounts for floating-point precision before truncating to integers so that the canvas will be the intended size.Fixes #27570
Fixes #15363
AI Disclosure
No AI was used
PR checklist