Download data underlying holoviews/bokeh plot


I am using holoviews with bokeh backend. I am wondering if there is a tool that allows to save data underlying a rendered bokeh plot?

There is a SaveTool, but it save a figure in png format. Instead I want to save the data underlying that plot.

I imagine, such tool may not be super easy as plots may get very complicated, but the example I have in mind is NdOverlay of Curves or Scatters. In this case this is just a dataframe. It would be cool to have a tool button that I can click and get underlying dataframe data saved as a csv file on disk or even in clipboard so that I can then load it for analysis in my notebook with pd.read_clipboard().

If such tool does not exist, can someone give suggestions how one would approach implementing this using bokeh/holoviews/panel in a relatively simple way. The reason I like the tool, as it is very minimalistic solution in terms of dependencies (e.g. I don’t need panel buttons to draw a plot from holoviews object) and also, for example, panel button will be external to the plot and this will take more space on a screen.

Hi @mshevelev

At least you can do it with Panel. And with Panel it will work no matter which library you are using for visualizing your dataframe.

You can use it in a notebook, served panel app or saved to a static .html file.

import panel as pn
import pandas as pd
import hvplot.pandas
from io import StringIO


data = {'x': [1, 2, 3, 4],
        'y': [5, 6, 7, 8]}
df = pd.DataFrame(data)

sio = StringIO()
df.to_csv(sio, index=False)

file_download = pn.widgets.FileDownload(sio, embed=True, filename='dataframe.csv', align="end")

plot = df.hvplot()

component = pn.Column(plot, file_download)"plot.html")

Hi @Marc , @mshevelev,

I was thinking about this the other day, what if you just wanted to download the data that is being shown in the graph rather than all the points out of view? I mean perhaps not the whole data frame but just the zoomed in portion? I have a feeling may be possible using tools related to stream, like tap or selection but I’ve not explored this, I’ve used to plot a graph from the tap to the right so I imagine it’s possible to grab the data in a callback and save with another button perhaps.

The above thought appears correct with the following links that may be useful and another example from Marc, thanks:

box select to return filtered dataframe
Holoviews BoundsX tool
filter tabulator post - could be useful

1 Like