Closed LuckyGem closed 7 years ago
Sorry for the delay, we really need to document this better. There are two ways of saving out data:
curve = hv.Curve(range(10)) # Could be any HoloViews object
renderer = hv.renderer('bokeh')
# Using renderer save
renderer.save(curve, 'graph.html')
# Convert to bokeh figure then save using bokeh
plot = renderer.get_plot(curve).state
from bokeh.io import output_file, save, show
save(plot, 'graph.html')
# OR
output_file("graph.html")
show(plot)
Wow, this should really be added to the Holoviews Userguide here! Thanks so much for explanation.
@philippjfr ,You gave an excellent answer. It helped me a lot. Thanks.
Note:
Only specify html
file name without an extension otherwise file will be saved as graph.html.html
.
eg.
curve = hv.Curve(range(10)) # Could be any HoloViews object
renderer = hv.renderer('bokeh')
# Using renderer save
renderer.save(curve, 'graph')
Hi @philippjfr - this is semi related.
The explanation was really helpful to me! I tried to use the same technique to store a hv.Scatter object using plotly as backed. (Because there is a sudden feature on the ploty scatter plot I prefer over the bokeh one.)
This is my attempt and observation:
# load libraries
import pandas as pd
import plotly
import holoviews as hv
hv.extension('plotly')
# generate holoviews scatter object
df = pd.DataFrame([[1,2,3],[4,5,6]]).T
df.columns = ['x', 'y']
obj = hv.Scatter(df, 'x', 'y')
First I tried:
hv.renderer('plotly').save(obj, 'output_1')
This generates a output_1.html file, but opened it in a webbrowser only shows a Drawing... webpage forever (png attached).
Then I tried:
objstate = hv.renderer('plotly').get_plot(obj).state
plotly.offline.plot(objstate, filename='output_2.html')
This generated a output_2.html file, which worked! (png attached).
I know that the plotly backed is beta and not fully supported yet. But It would be super cool if the first method would work too.
I just detected holoviews (and hvplot) lately. I am still quite noob to it and I have no idea where to start hacking in the code base to get this working. Maybe you can point me to the right part in the source code? Or otherwise I let it for the moment as a "improvement suggestion". Anyhow, till now I am really impressed with what is achievable with holoviews and hvplot.
Thank you very much, Elmar
Is it possible to convert time_series plot to html file?
Here's an example: No matter how I drug the time bar, the picture is same.
import xarray as xr
import hvplot
import hvplot.pandas
import hvplot.xarray
import geoviews as gv
import cartopy.crs as ccrs
import holoviews as hv
air_ds = xr.tutorial.open_dataset('air_temperature').load()
figure = air_ds.hvplot.quadmesh(
'lon', 'lat', 'air',projection=ccrs.PlateCarree(),cmap='viridis'
) * gv.feature.coastline * gv.feature.borders
handle = display(figure)
renderer = hv.renderer('bokeh')
renderer.save(figure, 'graph')
Note dynamic=False
, also we have a top-level save function now:
import xarray as xr
import hvplot
import hvplot.pandas
import hvplot.xarray
import geoviews as gv
import cartopy.crs as ccrs
import holoviews as hv
air_ds = xr.tutorial.open_dataset('air_temperature').load()
figure = air_ds.hvplot.quadmesh(
'lon', 'lat', 'air',projection=ccrs.PlateCarree(),cmap='viridis', dynamic=False
) * gv.feature.coastline * gv.feature.borders
hv.save(figure, 'graph.html')
@philippjfr Thanks! It works now 👍
Note
dynamic=False
, also we have a top-level save function now:import xarray as xr import hvplot import hvplot.pandas import hvplot.xarray import geoviews as gv import cartopy.crs as ccrs import holoviews as hv air_ds = xr.tutorial.open_dataset('air_temperature').load() figure = air_ds.hvplot.quadmesh( 'lon', 'lat', 'air',projection=ccrs.PlateCarree(),cmap='viridis', dynamic=False ) * gv.feature.coastline * gv.feature.borders hv.save(figure, 'graph.html')
do you have a top-level show function now?
I'm having trouble to save a linked plot as an html or some file format that I can simply share with others who don't use jupyter notebook. Here's the example from the doc.
import numpy as np
import holoviews as hv
hv.extension('bokeh')
# Declare some points
points = hv.Points(np.random.randn(1000,2 )).opts(tools=['box_select', 'lasso_select'])
# Declare points as source of selection stream
selection = hv.streams.Selection1D(source=points)
# Write function that uses the selection indices to slice points and compute stats
def selected_info(index):
arr = points.array()[index]
if index:
label = 'Mean x, y: %.3f, %.3f' % tuple(arr.mean(axis=0))
else:
label = 'No selection'
return points.clone(arr, label=label).opts(color='red')
# Combine points and DynamicMap
selected_points = hv.DynamicMap(selected_info, streams=[selection])
layout = points + selected_points
Is there any way to save the layout
together while the interactivity still working? So far, I have only figured out how to make a bokeh.application
.
DynamicMaps require a backend server, useful if you want to do computations on the go.
Since you're taking a mean of a selection of points, you can't export it as an HTML because there's additional computations to be made.
If you simply want a linked plot where you can select points and the corresponding points in other subplots get highlighted:
import holoviews as hv
hv.extension('bokeh')
df = pd.DataFrame({'x': [0, 1, 2], 'y': [4, 5, 6], 'z': [5, 7, 9]})
linked_plots = (
(hv.Scatter(df, 'x', 'y') + hv.Scatter(df, 'x', 'z') + hv.Table(df))
.opts('Scatter', tools=['lasso_select'], padding=0.5)
.opts(shared_datasource=True)
)
hv.save(linked_plots, 'linked_plots.html')
I have did the same as mentioned above, html file is saving and opening while trying from google colab.
But html saved while running the same code in Pycharm is not opening. Please share any idea or answer for the same. I have struck with this for an day
Its work with the latest version, If we have to use Python 3.6, bokeh version 2.11 and holoviews latest version worked for my work.
Sorry for the delay, we really need to document this better. There are two ways of saving out data:
curve = hv.Curve(range(10)) # Could be any HoloViews object renderer = hv.renderer('bokeh') # Using renderer save renderer.save(curve, 'graph.html') # Convert to bokeh figure then save using bokeh plot = renderer.get_plot(curve).state from bokeh.io import output_file, save, show save(plot, 'graph.html') # OR output_file("graph.html") show(plot)
Thanks, it works but remove styles.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I have a question about using holoviews and bokeh together to generate html file without using iPython Notebook. I have used bokeh before to generate interactive html file but I am not sure how to do it with holoviews. I want to have a time series graph and a dropdown menu(for example sales of fruit across year, the drop down menu will contain the different kind of frute), the graph will change according to fruite type. For example, if I want to have a time series graph, with bokeh alone we can plot=TimeSeries(data,index='Date',title="fruit X",ylabel='sales') output_file("graph.html") show(plot) I wonder if I can do something similar without using iPython Notebook? Really appreciate you help, thank you.