本文介绍了在散景中线性和对数刻度之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何重新生成此示例切换在线性刻度和对数刻度之间?

背景:我是Matplotlib的长期用户,最近的Bokeh用户.我开始使用Bokeh的主要原因之一是因为它提供了交互性.其中很大一部分是能够在绘图中的线性刻度和对数刻度之间进行切换的功能(这是我日常生活中真正需要的功能).在2015年此处解决了这个问题,当时还没有明确的答案./p>

但是,已经过了两年,我想知道是否有一种方法可以包含一个按钮/小部件,以将x和y轴的线性比例从对数刻度更改为对数刻度.如果没有,我肯定有一种干净的方法可以某种方式模拟这种行为(没有并排放置两个图).

解决方案

一种可能的解决方案是将线性图和对数图都放入Tabs中,例如:

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)

或者,您可以通过CustomJS回调连接bokeh.models.widgets.Button,从而更改绘图范围,但是对我来说,上面的内容似乎更容易一些.

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

解决方案

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.

这篇关于在散景中线性和对数刻度之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 20:02