Toggle log scale axis in DynamicMap?


I’m trying to create a DynamicMap driven by a checkbox widget to switch beteween linear and log scale y-axis.

I’ve had no luck so far, as clicking on the checkbox does not update the plot. I’ve tried using .apply:

checkbox = pn.widgets.Checkbox(name='Logscale', value=True)
dmap = hv.Scatter([1, 2, 3, 4, 5, 6, 7]).apply.opts(logy=checkbox.param.value)
pn.Column(dmap, checkbox)

Or a callback:

def make_plot(logscale):
    return hv.Scatter([1, 2, 3, 4, 5, 6, 7]).opts(logy=logscale)
dmap = hv.DynamicMap(pn.bind(make_plot, logscale=checkbox.param.value))
pn.Column(dmap, checkbox)

In both case I can make other opts work (such as color, size etc), is it the case that axes cannot be modified once the plot is rendered?

As an aside, if any admin reads this I had to create a new account because I cannot create new posts with the first one (Theom username). I have a draft which cannot be opened when clicking on it and cannot be deleted as I get the following error:

If possible I’d like to get back the ability to create new posts with the original account!

I don’t think it is possible to change between logscale and linspace for an existing plot inside DynamicMap. I have made an small example here (notice how the title changes):

import holoviews as hv
import panel as pn

checkbox = pn.widgets.Checkbox(name='Logscale', value=True)
scatter = lambda y: hv.Scatter([1, 2, 3, 4, 5, 6, 7]).opts(title=str(y), logy=y)
plot = pn.bind(scatter, checkbox)
dmap = hv.DynamicMap(plot)
pn.Column(checkbox, plot, dmap).servable()

It could be related to cnorm not updating in DynamicMap · Issue #5228 · holoviz/holoviews · GitHub.

Many thanks for you response.

I can’t see how the pn.bind works on its own while it doesn’t when wrapped in a DynamicMap but it’s enough for me, I’ll use a bare pn.bind as it suits my use case.

I would also expect it to work with DynamicMap. It could be an issue with the cache system of DynamicMap.

Try to make a bug report / feature request about it on Github. :slight_smile:

Ok sure, I will!

1 Like

Alright I see that you’ve already posted it, thanks

1 Like

I posted a problem related to the code I have posted above, but the issue is not about getting logarithmic axis to work with DynamicMap.

So I still think you should make a new issue/feature request about it.

Sorry, for the confusion.

1 Like