Thanks Tom!
My question is, would it be possible for the html to contain the
interactive MPL figure, as returned by the notebook backend? There's also
_repr_javascript_ it turns out.
But yes, this is already great, I can use this for _repr_png_.
I'm targeting 3.0+ so "new enough matplotlib" shouldn't be an issue. =)
Juan.
On Thu, Nov 8, 2018, at 11:16 AM, Thomas Caswell wrote:
Something like:
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvas
fig = Figure()
canvas = FigureCanvas(fig) # this step will be optional in mpl 3.1 (and
current master)
ax = fig.subplots() # assuming new enough matplotlib
or one of the other backends. If you are doing this for a htmlrepr you
likely want to also do
output = BytesIO()
fig.savefig(output, format='png')
to get the image as a buffer you can inject into the repr (or SVG?)
Hope that helps!
Tom
On Wed, Nov 7, 2018 at 4:38 PM Juan Nunez-Iglesias <jni.soma at gmail.com> > wrote:
Hi,
I'm working on a class to which I would like to add a _repr_html_ [1]
method for display in Jupyter notebooks. Is there a way to generate a
matplotlib notebook backend view "offline" (not using pyplot, since that
will behave differently depending on the currently active backend), and
then return the corresponding html?
Thanks,
Juan.
.. [1]:
https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users
--
Thomas Caswell
tcaswell at gmail.com