Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed as not planned
Closed as not planned
Description
When launching a jupyter notebook, the environment variableMPLBACKEND
is set to inline, but figures will still not be displayed in the output unless%matplotlib inline
orimport matplotlib.pyplot
is run. Both of these commands hook IPython to a function that gets triggered whenever a Figure is the output from a cell. This function is responsible for printing the figure to the screen.
Proposed solution:
A_repr_html_
method exists for figures, but is only implemented for webagg backends. Something like the following could be added to_repr_html_
.
ifrcParams['backend']=='module://ipykernel.pylab.backend_inline':fromioimportBytesIOfrombase64importb64encodepng_bytes=BytesIO()self.canvas.print_figure(png_bytes,format='png')s=png_bytes.getvalue()s1=b64encode(s).decode()returnf'<img src="data:image/png;base64,{s1}"/>'
This is@tacaswell's idea. I previously created an issue with IPython -ipython/ipython#12190 (comment)