Toggle between linear and log scale in bokeh

ⅰ亾dé卋堺 提交于 2020-01-11 11:52:07

问题


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).


回答1:


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.



来源:https://stackoverflow.com/questions/44813611/toggle-between-linear-and-log-scale-in-bokeh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!