matplotlib-pyodide
matplotlib-pyodide copied to clipboard
plt.figure() throws if not immediately followed by more plotting
I need this to set up the report markup (ideally I'd just have <figure id="somematplotlibfigureid" /> in html and then fill them up later) and do the plotting later.
%% py
import numpy as np
import matplotlib.pyplot as plt
%% py
plt.figure('figfoo')
plt.plot(np.arange(10), np.arange(10))
plt.show()
# works
%% py
plt.figure('figbar')
# throws
# <Figure size 640x480 with 0 Axes>
# A value renderer encountered an error.
# TypeError: r.propertyIsEnumerable is not a function
#
# in t
# in t
# in t
# in t
# in v
# in div
# in Styled(div)
# in he
# in qt
# in div
# in Styled(div)
# in div
# in Styled(div)
# in bn
# in jn
# in p
# in div
# in div
# in div
# in ir
# in p
# in div
# in u
# in p
# in lr
# in p
# in t
# in p
# Please file a bug report.
I think it's just that the value renderer is choking on the Figure object. There's work ongoing on the Iodide side to clean up the reps and make them less likely to error out like this.
Does fig = plt.figure('figbar') instead work for you?
@mdboom It does work. Thanks!
On the side not, is there a way to bind a matplotlib figure to an existing HTML element?
Not at present -- we'd have to modify things slightly to support passing on the element (or at least an element id) into the Canvas class.