Reputation: 3507
How can I re-generate this example toggling between linear and log scales?
Background: I'm a long-time Matplotlib user, recent Bokeh user. One of the main reasons I have started using Bokeh is because of the interactiveness it provides. A big part of it would be the ability to toggle between linear and log scales in plots (which is something I really need in my daily life). This question was adressed here in 2015 and at the time there was no clear answer.
However, it's 2 years later and I'm wondering if there's a way to include a button/widget to change from linear to log scale for both the x and the y axes. If there isn't, I'm certain that there is a clean way to simulate that behavior in some way (without having two plots side-by-side).
Upvotes: 3
Views: 2181
Reputation: 2137
One potential solution is the put both linear and log plots into Tabs like:
from bokeh.plotting import figure, show
from bokeh.models.widgets import Tabs, Panel
panels = []
for axis_type in ["linear", "log"]:
fig = figure(x_axis_type=axis_type, y_axis_type=axis_type)
fig.scatter(x=[1,10,100,1000], y=[1,10,100,1000])
panel = Panel(child=fig, title=axis_type)
panels.append(panel)
tabs = Tabs(tabs=panels)
show(tabs)
Alternatively, you wire up a bokeh.models.widgets.Button
with a CustomJS callback that changes the plot ranges, but the above seems a little easier to me.
Upvotes: 1