vandel
vandel

Reputation: 71

Display an interactive panel with date slider to display individual dictionary element matplotlib figures with dates as keys

I have generated a dictionary of 3d Figures in Matplotlib named curve_dict

{numpy.datetime64('2022-07-11'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-12'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-13'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-14'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-17'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-18'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-19'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-20'): <Figure size 720x720 with 1 Axes>,
 numpy.datetime64('2022-07-21'): <Figure size 720x720 with 1 Axes>}

Each individual figure looks something like this:

Test image

For 2D items I have used Holoviews hmap to build and save an interactive dashboard that has a slider for the dictionary key that works well and generates static html when saved that I can place on a webpage for display and to interact with it from the static generated html.

Have not been able to do the same with matplotlib figures and not sure what direction to take to solve the problem. Have looked at matplotlib interactivity, ipywidgets and panel and have not found the secret sauce yet.

The problem is how to set up an interactive visualization that will select the figure for display from the dictionary based on a slider with date values, that can then be saved as static html and maintain interactivity

Any input is appreciated.

Based on Comments, Thank You! I have generated the panel using

slider = pn.widgets.DiscreteSlider(options=curve_dict,name="Analysis Date")

@pn.depends(slider.param.value)
def callback(value):
    return value

col = pn.Column(slider, callback)
col.embed()

But still have a loose end involving, something I must not have loaded as

pn.save('newtest.html',resources=INLINE)

yields

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [34], in <cell line: 10>()
      7 col = pn.Column(slider, callback)
      8 col.embed()
---> 10 pn.save('newtest.html',resources=INLINE)

AttributeError: module 'panel' has no attribute 'save'

All input is appreciated...

OK, found that save is an attribute of Column so now

col.save(filename='newtest.html',resources=INLINE)

Yields html file, but interactivity is lost ...slider moves but figure does not update.

Again all input is appreciated

Upvotes: 0

Views: 610

Answers (1)

vandel
vandel

Reputation: 71

Have found that this ...

from bokeh.resources import INLINE

slider = pn.widgets.DiscreteSlider(options=curve_dict,name="Analysis Date")

@pn.depends(slider.param.value)
def callback(value):
    return value

col = pn.Column(slider,callback)

col.save(filename='newtest1.html',resources=INLINE,embed=True)

Works.

Thanks for all input, much appreciated ....

Upvotes: 0

Related Questions