fix: resolve FigureCanvasTkAgg clipping on Windows HiDPI#31133
fix: resolve FigureCanvasTkAgg clipping on Windows HiDPI#31133timhoffm merged 9 commits intomatplotlib:mainfrom
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. You can also join us on gitter for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
I think I understand how this works, but it feels like there should be a better way in tk for widgets to be notified that their size is changed. We should be using that mechanism (possibly re-working how we currently do it) instead#. |
Thanks @tacaswell , I see what you mean. I’ll try to find a better Tk-native way for widgets to react to size changes and rework the current approach based on that. |
… fix/issue-31126
…resizing with actual widget dimensions instead of computed ones after DPI changes
|
@tacaswell @sanrishi Please review the PR and let me know your feedback. Thanks! |
|
please any update for me. thanks |
|
Running the example code from #31126 on linux with X11 and hi-dpi I get and it renders correctly. vs the buggy case which renders clipped but on manually resizing fixes itself. |
tacaswell
left a comment
There was a problem hiding this comment.
Manually verified that this fixes the problem and the fix makes sense.
Would like an explanation of the commit history before we merge.
Thanks for approving. What should I do on my end? I don't understand your mention |
|
There are commits from both @intelliking @statxc in the commit history. We are very much in favor of collaboration (it is the main thing we do here), but I also want to make sure everyone involved is aware they are involved etc. [I had a comment asking about this in another tab and failed to post it before my review] |
|
@tacaswell Ah, I understand now. At first, my username was @intelliking. After that, I changed username to @statxc . @statxc and @intelliking are same - Me. Sorry for confusion. 🙏 |
| width, height = event.width, event.height | ||
| self._resize_canvas(event.width, event.height) | ||
|
|
||
| def _resize_canvas(self, width, height): |
There was a problem hiding this comment.
This should have a docstring
| def _resize_canvas(self, width, height): | |
| def _resize_canvas(self, width, height): | |
| """Update figure size and redraw based on a given canvas size.""" |
Also, the name _resize_canvas is a bit vague. Should this be _resize_figure_for_canvas_size?
| # canvas backing store on that event. | ||
| # The easiest way to resize the canvas is to emit a | ||
| # resize event since we implement all the logic for resizing | ||
| # the canvas backing store on that event. |
There was a problem hiding this comment.
Is the description correct? Isn't it primarily that we set the canvas size and then explicitly update the figure size using _resize_canvas (or possibly better named _resize_figure_for_canvas_size())? The event seems now an implementation detail of the called _resize_... method and seems to not be relevant here anymore.
|
Thanks @statxc ! |
PR summary
Closes #31126
Why is this change necessary?
FigureCanvasTkAggembedded in layout-managed containers renders plots larger than the visible area, clipping axis labels and legends.What problem does it solve?
<Configure>event from firing and leavingfigure.size_inchesmiscalculated, causing the render buffer to exceed the visible canvas size.What is the reasoning for this implementation?
resize()to recalculatefigure.size_incheswith the correct DPI, ensuring render size matches visible size.PR checklist