Skip to content

Scaling issue with 4K panel! #12221

Closed
Closed

Description

@Khalilsqu

Matplotlib plots and font size looks very small on 4K monitor.

Is there away to automatically enable high DPI?

capture

Activity

  1. jklymak commented on Sep 23, 2018

    @jklymak
    Member

    We'd need a lot more information before we can tell if this is a bug or not. Thanks!

  2. Khalilsqu commented on Sep 24, 2018

    @Khalilsqu
    Author

    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!!

    import sys
    import matplotlib
    import ctypes
    user32 = ctypes.windll.user32
    user32.SetProcessDPIAware()
    [w, h] = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]
    
    print("screen resolution is {} by {}".format(w,h))
    
    print(sys.platform)
    print(sys.version)
    
    print(matplotlib.__version__)
    print(matplotlib.get_backend())
    
    import matplotlib.pyplot as plt
    
    plt.plot(range(100))
    
    plt.show()
    

    4k

    But when I lower the screen resolution to FHD, 1920x1080 in the windows setting, the figures and font sizes becomes normal and good!

    fhd

    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

  3. jklymak commented on Sep 24, 2018

    @jklymak
    Member

    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):

  4. ImportanceOfBeingErnest commented on Sep 24, 2018

    @ImportanceOfBeingErnest
    Member

    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, 
    
  5. Khalilsqu commented on Sep 24, 2018

    @Khalilsqu
    Author

    @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

  6. ImportanceOfBeingErnest commented on Sep 24, 2018

    @ImportanceOfBeingErnest
    Member

    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.

  7. jklymak commented on Sep 24, 2018

    @jklymak
    Member

    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.

  8. Khalilsqu commented on Sep 24, 2018

    @Khalilsqu
    Author

    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?

    spyder-ide/spyder#4316
    https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/

  9. jklymak commented on Sep 24, 2018

    @jklymak
    Member

    Thanks - so far as I can see we already do "Case II" in the blog post about QT above:

    if is_pyqt5():
    try:
    qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
    qApp.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)

    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.

  10. 69 remaining items

  11. added this to the v3.7.1 milestone on Feb 14, 2023
  12. modified the milestones: v3.7.1, v3.7.2 on Mar 4, 2023
  13. modified the milestones: v3.7.2, v3.7.3 on Jul 5, 2023
  14. karahanyilmazer commented on Aug 16, 2023

    @karahanyilmazer

    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

  15. modified the milestones: v3.7.3, v3.8.0 on Sep 9, 2023
  16. removed this from the v3.8.0 milestone on Sep 15, 2023
  17. github-actions commented on Sep 27, 2024

    @github-actions

    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!

  18. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Sep 27, 2024
  19. tacaswell commented on Aug 21, 2025

    @tacaswell
    Member

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions