@@ -357,6 +357,7 @@ def __init__(self,
357357 self .dpi_scale_trans = Affine2D ().scale (dpi , dpi )
358358 # do not use property as it will trigger
359359 self ._dpi = dpi
360+ self ._original_dpi = dpi
360361 self .bbox = TransformedBbox (self .bbox_inches , self .dpi_scale_trans )
361362
362363 self .frameon = frameon
@@ -964,13 +965,37 @@ def set_facecolor(self, color):
964965 """
965966 self .patch .set_facecolor (color )
966967
967- def set_dpi (self , val ):
968+ def set_dpi (self , dpi ):
968969 """
969- Set the resolution of the figure in dots-per-inch.
970+ Set the nominal resolution of the figure in dots-per-inch.
970971
971- .. ACCEPTS: float
972- """
973- self .dpi = val
972+ Parameters
973+ ----------
974+ dpi : float
975+
976+ Notes
977+ -----
978+ Some backends have the concept of "hi-dpi" displays (or "Retina")
979+ where the resolution is doubled, but dimensions are traditionally
980+ specified as if the resolution were not doubled. Some Matplotlib
981+ GUI backends respect this doubling (i.e. Qt5Agg), but Matplotlib still
982+ specifies dimensions and dpi to matplotlib as if the resolution
983+ were not doubled. The default figure
984+ value is nominally 100 dpi, but displays that are deignated "hi-dpi"
985+ will internally double this to 200 dpi. We keep the "nominal" dpi
986+ because some computer set ups have one display at normal dpi, and a
987+ second at hi-dpi, so a nominal resolution must be stored to stop
988+ figures from doubling or halving is size when moved between displays.
989+ """
990+
991+ # some backends set self._dpi to be a ratio times
992+ # self._original_dpi:
993+ ratio = self ._dpi / self ._original_dpi
994+
995+ # _original_dpi is the nominal dpi before any hi-dpi changes.
996+ self ._original_dpi = dpi
997+ # calls _set_dpi with the actual display dpi...
998+ self .dpi = dpi * ratio
974999 self .stale = True
9751000
9761001 def set_figwidth (self , val , forward = True ):
0 commit comments