You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when I lower the screen resolution to FHD, 1920x1080 in the windows setting, the figures and font sizes becomes normal and good!
So, my question is how I can configure matplotlib to plot similarly both in UHD or FHD without the need to make changes in the code or use dragging. Please check the screen resolution in the code output shown in both figures above!. Dragging only makes plot bigger but font size of tick labels stay the same, unless I change them in the code
Qt5Agg should automatically detect if the screen dpi is doubled. It calls window.devicePixelRatio(). So, maybe your setup is too old to do that (2.2.3 does this, but I guess some old Qt5 versions don't) or your device isn't reporting that its pixel doubled.
If you want to set the dpi by hand, you can set the dpi rcParam.
If you want to debug, you can edit backend_qt5agg and put some print statements in def _dpi_ratio(self):
I think there is a fundamental difference between macOS and the rest of the world (or between HighDPI and high dpi). Macs may scale the dpi, effectively showing the application in a virtual dpi space. Windows does not do that. There is just one dpi; but it might instead use different profiles such that some relevant metrics are scaled by a constant factor (e.g. a 12pt font will become 24pt).
I suppose this article is relevant here. Possibly this blog post as well.
If I understand the above article correctly the application attribute Qt::AA_EnableHighDpiScaling could be used; but I'm not sure how that would play with the manual settings currently done within the qt painter method.
It was also reported that on windows devicePixelRatio() always returns 1 and a potential workaround would be to use logicalDpiX() instead.
One might think about making the _dpi_ratio publically available to the user and adjustable via rcParams.
For the time being the only option seems to be to change the true dpi, e.g. in this case the rc file may be changed to
figure.dpi : 200
savefig.dpi : 100 # to avoid large graphics when saving,
@ImportanceOfBeingErnest Thank you very much. actually matplotlib.rcParams['figure.dpi'] = 200 is the solution worked for me. tried tk, etc yet all cannot scale properly on 4K screen
Reopening, because this is surely a desireable feature, given that matplotlib goes through all the trouble of using different dpi values on different levels, but apparently only mac users will benefit from it.
Reacted by Khalil Al Hooti, bjfar and Karahan Yılmazer
I actually thinks it’s a pain that the Mac does this rather than just stating its true dpi. The advantage of allowing it to change is dragging between screens w different dpi. But in my opinion we should just get the dpi from the device at draw time.
There was a similar issue in spyder ide but recently solved in their latest releases. Spyder is basically using Qt5. I experienced scaling issue with spyder using 4K screen but resolved by enabling Enable auto high scaling in spyder settings. probably a similar approach could be applied to Matplotlib?
So its odd that its not working for Qt5, unless you have an old Qt5, an environment variable set, or are somehow disabling this. You could download master and put a print statement above to see if your Qt5 has the correct attribute.
Are there any news regarding this issue? Still having high-DPI related problems on VS Code and I need to paste a chunk of code in the beginning of each script to overcome the issue. Thank you!
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
I'm going to close this as the discussion is very long and we think that most of the hi-dpi related issues have been resolved. Any new issues are likely to be different than are discussed here as the ground has moved under us (e.g. Qt has done atleast 2 generations of revisions of their API for hi-dpi).
Activity
jklymak commentedon Sep 23, 2018
We'd need a lot more information before we can tell if this is a bug or not. Thanks!
Khalilsqu commentedon Sep 24, 2018
I recently purchased a new pc laptop with 4K resolution touch screen.
when I run the following code while screen is at native max resolution of 4K. pyplot images and font sizes are displayed very tiny!!
But when I lower the screen resolution to FHD, 1920x1080 in the windows setting, the figures and font sizes becomes normal and good!
So, my question is how I can configure matplotlib to plot similarly both in UHD or FHD without the need to make changes in the code or use dragging. Please check the screen resolution in the code output shown in both figures above!. Dragging only makes plot bigger but font size of tick labels stay the same, unless I change them in the code
jklymak commentedon Sep 24, 2018
Qt5Agg should automatically detect if the screen dpi is doubled. It calls
window.devicePixelRatio(). So, maybe your setup is too old to do that (2.2.3 does this, but I guess some old Qt5 versions don't) or your device isn't reporting that its pixel doubled.If you want to set the dpi by hand, you can set the
dpircParam.If you want to debug, you can edit backend_qt5agg and put some print statements in
def _dpi_ratio(self):ImportanceOfBeingErnest commentedon Sep 24, 2018
I think there is a fundamental difference between macOS and the rest of the world (or between HighDPI and high dpi). Macs may scale the dpi, effectively showing the application in a virtual dpi space. Windows does not do that. There is just one dpi; but it might instead use different profiles such that some relevant metrics are scaled by a constant factor (e.g. a 12pt font will become 24pt).
I suppose this article is relevant here. Possibly this blog post as well.
If I understand the above article correctly the application attribute
Qt::AA_EnableHighDpiScalingcould be used; but I'm not sure how that would play with the manual settings currently done within the qt painter method.It was also reported that on windows
devicePixelRatio()always returns1and a potential workaround would be to uselogicalDpiX()instead.One might think about making the
_dpi_ratiopublically available to the user and adjustable viarcParams.For the time being the only option seems to be to change the true dpi, e.g. in this case the rc file may be changed to
Khalilsqu commentedon Sep 24, 2018
@ImportanceOfBeingErnest Thank you very much. actually
matplotlib.rcParams['figure.dpi'] = 200is the solution worked for me. tried tk, etc yet all cannot scale properly on 4K screenImportanceOfBeingErnest commentedon Sep 24, 2018
Reopening, because this is surely a desireable feature, given that matplotlib goes through all the trouble of using different dpi values on different levels, but apparently only mac users will benefit from it.
jklymak commentedon Sep 24, 2018
I actually thinks it’s a pain that the Mac does this rather than just stating its true dpi. The advantage of allowing it to change is dragging between screens w different dpi. But in my opinion we should just get the dpi from the device at draw time.
Khalilsqu commentedon Sep 24, 2018
There was a similar issue in spyder ide but recently solved in their latest releases. Spyder is basically using Qt5. I experienced scaling issue with spyder using 4K screen but resolved by enabling
Enable auto high scalingin spyder settings. probably a similar approach could be applied to Matplotlib?spyder-ide/spyder#4316
https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/
jklymak commentedon Sep 24, 2018
Thanks - so far as I can see we already do "Case II" in the blog post about QT above:
matplotlib/lib/matplotlib/backends/backend_qt5.py
Lines 127 to 130 in 2125562
So its odd that its not working for Qt5, unless you have an old Qt5, an environment variable set, or are somehow disabling this. You could download master and put a print statement above to see if your Qt5 has the correct attribute.
69 remaining items
karahanyilmazer commentedon Aug 16, 2023
Are there any news regarding this issue? Still having high-DPI related problems on VS Code and I need to paste a chunk of code in the beginning of each script to overcome the issue. Thank you!
@tacaswell @QuLogic @oscargus
github-actions commentedon Sep 27, 2024
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
tacaswell commentedon Aug 21, 2025
I'm going to close this as the discussion is very long and we think that most of the hi-dpi related issues have been resolved. Any new issues are likely to be different than are discussed here as the ground has moved under us (e.g. Qt has done atleast 2 generations of revisions of their API for hi-dpi).