-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: fix figure.set_dpi when pixel ratio not 1 #11232
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,6 +357,7 @@ def __init__(self, | |
self.dpi_scale_trans = Affine2D().scale(dpi, dpi) | ||
# do not use property as it will trigger | ||
self._dpi = dpi | ||
self._original_dpi = dpi | ||
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans) | ||
|
||
self.frameon = frameon | ||
|
@@ -964,13 +965,44 @@ def set_facecolor(self, color): | |
""" | ||
self.patch.set_facecolor(color) | ||
|
||
def set_dpi(self, val): | ||
def set_dpi(self, dpi): | ||
""" | ||
Set the resolution of the figure in dots-per-inch. | ||
Set the nominal resolution of the figure in dots-per-inch. | ||
|
||
.. ACCEPTS: float | ||
""" | ||
self.dpi = val | ||
This is nominal because some screens have "hi-dpi" or "Retina", | ||
where pixels are doubled. This dpi is the non-doubled value. | ||
|
||
Setting the dpi different from your screen dpi makes the figure larger | ||
or smaller on the screen than the width and height specified in | ||
`~.Figure.get_width_height`. | ||
|
||
Parameters | ||
---------- | ||
dpi : float | ||
|
||
Notes | ||
----- | ||
Some backends have the concept of "hi-dpi" displays (or "Retina") | ||
where the resolution is doubled, but dimensions are traditionally | ||
specified as if the resolution were not doubled. Some Matplotlib | ||
GUI backends respect this doubling (i.e. Qt5Agg), but Matplotlib still | ||
specifies dimensions and dpi to matplotlib as if the resolution | ||
were not doubled. The default figure | ||
value is nominally 100 dpi, but displays that are deignated "hi-dpi" | ||
will internally double this to 200 dpi. We keep the "nominal" dpi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not quite true, we also need to save the original to drop back to the correct dpi for savefig with |
||
because some computer set ups have one display at normal dpi, and a | ||
second at hi-dpi, so a nominal resolution must be stored to stop | ||
figures from doubling or halving is size when moved between displays. | ||
""" | ||
|
||
# some backends set self._dpi to be a ratio times | ||
# self._original_dpi: | ||
ratio = self._dpi / self._original_dpi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that we want to rely on this here. I can not produce one off the top of my head, but this feels like it is prone to race conditions. This dpi doubling is the business of the GUI backends and I would like to keep as much of it there as possible. What we should do is set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well race conditions can maybe be cured by clamping down the API a bit. See discussion above. The We could temporarily set the dpi to twice at draw time.... Hmmmm. let me look into that.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, no its not that simple because of interactivity. I think it really is better to actually set the dpi for the figure object so it knows its actual rendered dpi.... |
||
|
||
# _original_dpi is the nominal dpi before any hi-dpi changes. | ||
self._original_dpi = dpi | ||
# calls _set_dpi with the actual display dpi... | ||
self.dpi = dpi * ratio | ||
self.stale = True | ||
|
||
def set_figwidth(self, val, forward=True): | ||
|
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.
Please don't change argument names, it will break people doing
**kwargs
into it.