File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -86,8 +86,11 @@ def export(self):
86
86
# Figure width in pixels
87
87
pwidth = (self .canvas .figure .get_figwidth () *
88
88
self .canvas .figure .get_dpi ())
89
- # Scale size to match widget on HiPD monitors
90
- width = pwidth / self .canvas ._dpi_ratio
89
+ # Scale size to match widget on HiDPI monitors.
90
+ if hasattr (self .canvas , 'device_pixel_ratio' ): # Matplotlib 3.5+
91
+ width = pwidth / self .canvas .device_pixel_ratio
92
+ else :
93
+ width = pwidth / self .canvas ._dpi_ratio
91
94
data = "<img src='data:image/png;base64,{0}' width={1}/>"
92
95
data = data .format (b64encode (buf .getvalue ()).decode ('utf-8' ), width )
93
96
display (HTML (data ))
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ export class MPLCanvasModel extends widgets.DOMWidgetModel {
72
72
send_initialization_message ( ) {
73
73
if ( this . ratio != 1 ) {
74
74
this . send_message ( 'set_dpi_ratio' , { dpi_ratio : this . ratio } ) ;
75
+ this . send_message ( 'set_device_pixel_ratio' , {
76
+ device_pixel_ratio : this . ratio ,
77
+ } ) ;
75
78
}
76
79
77
80
this . send_message ( 'send_image_mode' ) ;
You can’t perform that action at this time.
0 commit comments