gpt4 book ai didi

python - 带有 DataRange1d 的 Bokeh 双轴不能很好地缩放

转载 作者:太空宇宙 更新时间:2023-11-04 09:49:02 28 4
gpt4 key购买 nike

我想在双轴图上绘制一些数据,我在文档中找到了 example ,但我需要动态范围 (DataRange1d),因为我的数据在可视化过程中会发生变化,而且我事先不知道它会是什么。

我的问题:两个 y 范围具有相同的缩放比例,并且被锁定在一起:我不能只缩小一个范围。

from numpy import pi, arange, sin, linspace
from bokeh.plotting import show
from bokeh.models import LinearAxis, Range1d, DataRange1d
from bokeh.models import Plot, Title, PanTool, WheelZoomTool
from bokeh.models import Circle, ColumnDataSource

# get some data
x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
y2 = linspace(0, 100, len(y))

# configure plot
p = Plot(title = Title(text="Titre"), x_range = DataRange1d(), y_range = DataRange1d())
p.add_tools(PanTool(), WheelZoomTool())
p.add_layout(LinearAxis(), "below")
p.add_layout(LinearAxis(), "left")

# add extra y range
p.extra_y_ranges = {"foo": DataRange1d()}
p.add_layout(LinearAxis(y_range_name="foo"), 'right')

# plot using both axes
cds = ColumnDataSource(data=dict(x=x, y=y, y2=y2))
c1 = Circle(x="x", y="y", line_color="red", fill_color="red")
p.add_glyph(cds, c1)
c2 = Circle(x="x", y="y2", line_color="blue", fill_color="blue")
p.add_glyph(cds, c2, y_range_name="foo")

show(p)

bokeh plot

最佳答案

默认情况下,DataRange1d 使用所有渲染器计算其开始和结束。但是您可以指定要使用的渲染器:

[...]

c1 = Circle(x="x", y="y", line_color="red", fill_color="red")
c1_renderer = p.add_glyph(cds, c1)
p.y_range.renderers = [c1_renderer]

c2 = Circle(x="x", y="y2", line_color="blue", fill_color="blue")
c2_renderer = p.add_glyph(cds, c2, y_range_name="foo")
p.extra_y_ranges['foo'].renderers = [c2_renderer]

[...]

关于python - 带有 DataRange1d 的 Bokeh 双轴不能很好地缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48631530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com