Skip to content

Commit d1db13a

Browse files
committed
Set size of static figure to match widget on hidp displays
This was lost in the trasition to the widget based backend
1 parent 0c07515 commit d1db13a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ class NavigationIPy(NavigationToolbar2WebAgg):
122122
def export(self):
123123
buf = io.BytesIO()
124124
self.canvas.figure.savefig(buf, format='png', dpi='figure')
125-
data = "<img src='data:image/png;base64,{0}'/>"
126-
data = data.format(b64encode(buf.getvalue()).decode('utf-8'))
125+
# Figure width in pixels
126+
pwidth = self.canvas.figure.get_figwidth()*self.canvas.figure.get_dpi()
127+
# Scale size to match widget on HiPD monitors
128+
width = pwidth/self.canvas._dpi_ratio
129+
data = "<img src='data:image/png;base64,{0}' width={1}/>"
130+
data = data.format(b64encode(buf.getvalue()).decode('utf-8'), width)
127131
display(HTML(data))
128132

129133

0 commit comments

Comments
 (0)