Skip to content

Commit 9fdde67

Browse files
committed
Handle new FigureCanvasBase.device_pixel_ratio.
This is a corollary to matplotlib/matplotlib#19126.
1 parent a923ae8 commit 9fdde67

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ipympl/backend_nbagg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ def export(self):
8686
# Figure width in pixels
8787
pwidth = (self.canvas.figure.get_figwidth() *
8888
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
9194
data = "<img src='data:image/png;base64,{0}' width={1}/>"
9295
data = data.format(b64encode(buf.getvalue()).decode('utf-8'), width)
9396
display(HTML(data))

js/src/mpl_widget.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export class MPLCanvasModel extends widgets.DOMWidgetModel {
7272
send_initialization_message() {
7373
if (this.ratio != 1) {
7474
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+
});
7578
}
7679

7780
this.send_message('send_image_mode');

0 commit comments

Comments
 (0)