Closed as not planned
Closed as not planned
Description
When launching a jupyter notebook, the environment variable MPLBACKEND
is set to inline, but figures will still not be displayed in the output unless %matplotlib inline
or import 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_
.
if rcParams['backend'] == 'module://ipykernel.pylab.backend_inline':
from io import BytesIO
from base64 import b64encode
png_bytes = BytesIO()
self.canvas.print_figure(png_bytes, format='png')
s = png_bytes.getvalue()
s1 = b64encode(s).decode()
return f'<img src="data:image/png;base64, {s1}"/>'
This is @tacaswell's idea. I previously created an issue with IPython - ipython/ipython#12190 (comment)