-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix Cairo backends on HiDPI screens #21025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
So Cairo doesn't support mixed dpi screen setups? |
lib/matplotlib/tests/test_figure.py
Outdated
fig.savefig(buf, format='png') | ||
ratio2 = Image.open(buf) | ||
|
||
assert ratio1.size == ratio2.size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess even the whole images should be the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but they're empty figures, so I didn't bother. I thought of using check_figures_equal
, but I don't know how to force a different backend with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could actually plot something, and do a plain rgba array equality check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a mixed dpi setup to test, but at least for single-screen simulated highdpi, this does what it says on the tin.
If you mean multiple screens, that's handled at the canvas level. If you mean something like PDF, I'm not sure, but I think the Agg/PDF backends are just as broken. |
Yeah I meant screen one is non-retina and screen two is retina, and you drag the window from one to the other. |
Yes, that depends on the backend supporting it, but e.g., QtCairo does support that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked locally and confirmed that the fix works
Unlike the Agg renderer, the Cairo renderer exists forever and is at the DPI when the figure was created. This needs to be updated before drawing or things in physical sizes (e.g., text or line widths) will be the wrong size.
Otherwise, `FigureCanvasBase.get_width_height` returns a size scaled down by the current pixel ratio, even though the DPI is not scaled up. This causes the saved figure to be cropped.
db759fd
to
9598205
Compare
…025-on-v3.5.x Backport PR #21025 on branch v3.5.x (Fix Cairo backends on HiDPI screens)
PR Summary
Since Cairo renderers exist forever, we need to ensure they are using the correct DPI, or else physical sizes are incorrect.
Fixes #21024.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).