Hi @doronbehar
Welcome to the community.
I don’t know how you can use an existing Matplotlib Figure.
Some strategies for showing the Matplotlib figure is
- To save the figure (as you described) does not work for you.
- Use Figure.show() which is really only useful in Notebook or ipython terminal
- Use Panel to serve or show the figure
Figure.show()
import hvplot.pandas
import pandas as pd
from matplotlib.figure import Figure
import holoviews as hv
import panel as pn
df = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [10, 20, 30, 40]
})
plot = df.hvplot('x', 'y')
fig = hv.render(plot, backend='matplotlib')
fig.show()
Please not that Python will continue past the fig.show()
line and finish the script unless you are in ipython console or notebook.
Panel .servable()
import hvplot.pandas
import pandas as pd
from matplotlib.figure import Figure
import holoviews as hv
import panel as pn
pn.extension()
df = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [10, 20, 30, 40]
})
plot = df.hvplot('x', 'y')
fig = hv.render(plot, backend='matplotlib')
pn.pane.Matplotlib(fig, height=500, width=500).servable()
panel serve script.py --dev
Personally I would use the script below because its shorter.
import hvplot.pandas
import pandas as pd
from matplotlib.figure import Figure
import holoviews as hv
import panel as pn
pn.extension()
df = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [10, 20, 30, 40]
})
plot = df.hvplot('x', 'y')
pn.pane.HoloViews(plot, height=500, width=500, backend="matplotlib").servable()
Panel .show()
import hvplot.pandas
import pandas as pd
from matplotlib.figure import Figure
import holoviews as hv
import panel as pn
pn.extension()
df = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [10, 20, 30, 40]
})
plot = df.hvplot('x', 'y')
fig = hv.render(plot, backend='matplotlib')
pn.pane.Matplotlib(fig, height=500, width=500).show()
python script.py