@@ -357,6 +357,7 @@ def __init__(self,
357
357
self .dpi_scale_trans = Affine2D ().scale (dpi , dpi )
358
358
# do not use property as it will trigger
359
359
self ._dpi = dpi
360
+ self ._original_dpi = dpi
360
361
self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
361
362
362
363
self .frameon = frameon
@@ -964,13 +965,44 @@ def set_facecolor(self, color):
964
965
"""
965
966
self .patch .set_facecolor (color )
966
967
967
- def set_dpi (self , val ):
968
+ def set_dpi (self , dpi ):
968
969
"""
969
- Set the resolution of the figure in dots-per-inch.
970
+ Set the nominal resolution of the figure in dots-per-inch.
970
971
971
- .. ACCEPTS: float
972
- """
973
- self .dpi = val
972
+ This is nominal because some screens have "hi-dpi" or "Retina",
973
+ where pixels are doubled. This dpi is the non-doubled value.
974
+
975
+ Setting the dpi different from your screen dpi makes the figure larger
976
+ or smaller on the screen than the width and height specified in
977
+ `~.Figure.get_width_height`.
978
+
979
+ Parameters
980
+ ----------
981
+ dpi : float
982
+
983
+ Notes
984
+ -----
985
+ Some backends have the concept of "hi-dpi" displays (or "Retina")
986
+ where the resolution is doubled, but dimensions are traditionally
987
+ specified as if the resolution were not doubled. Some Matplotlib
988
+ GUI backends respect this doubling (i.e. Qt5Agg), but Matplotlib still
989
+ specifies dimensions and dpi to matplotlib as if the resolution
990
+ were not doubled. The default figure
991
+ value is nominally 100 dpi, but displays that are deignated "hi-dpi"
992
+ will internally double this to 200 dpi. We keep the "nominal" dpi
993
+ because some computer set ups have one display at normal dpi, and a
994
+ second at hi-dpi, so a nominal resolution must be stored to stop
995
+ figures from doubling or halving is size when moved between displays.
996
+ """
997
+
998
+ # some backends set self._dpi to be a ratio times
999
+ # self._original_dpi:
1000
+ ratio = self ._dpi / self ._original_dpi
1001
+
1002
+ # _original_dpi is the nominal dpi before any hi-dpi changes.
1003
+ self ._original_dpi = dpi
1004
+ # calls _set_dpi with the actual display dpi...
1005
+ self .dpi = dpi * ratio
974
1006
self .stale = True
975
1007
976
1008
def set_figwidth (self , val , forward = True ):
0 commit comments