ENH: Add HiDPI physical to logical pixel ratio property · Issue #14405 · matplotlib/matplotlib · GitHub
Skip to content

ENH: Add HiDPI physical to logical pixel ratio property #14405

Description

@larsoner

When writing figure resizing code to set subplot sizes, HiDPI screens can mess things up if the physical to logical pixel ratio is not accounted for. On the Qt5 backend, there is fig.canvas. _dpi_ratio and on MacOSX there is fig.canvas._device_scale that expose the physical to logical pixel ratio. This leads to code like this:

    dpi_ratio = 1.
    for key in ('_dpi_ratio', '_device_scale'):
        dpi_ratio = getattr(params["fig"].canvas, key, dpi_ratio)

I propose adding a dpi_ratio or similar property to fig.canvas or perhaps directly fig. For most backends it would just be 1. but Qt5Agg and MacOSX canvases could give their actual values.

Thoughts? I can take a stab at this if it seems worthwhile. Pointers as to the preferred name and whether it should live at the fig or fig.canvas level welcome.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions