【问题标题】:How to match the axes of two plots with Bokeh?如何将两个绘图的轴与散景匹配?
【发布时间】:2021-08-10 18:14:39
【问题描述】:

我有 2 个地块...

vwc_fig = figure(plot_width=1200, plot_height=400, title="Volumetric Water Content",
                x_axis_type="datetime",
                )
vwc_fig2 = figure(plot_width=1200, plot_height=400, title="Volumetric Water Content",
                 x_axis_type="datetime",
                 )

然后我设置数据...

pr = vwc_fig.line(x="date_time", y="P3_VWC",
            legend_label = 'pine road 45 cm',
             line_color = 'blue',
            source=pine_rd_df)
l = vwc_fig2.line(x="date_time", y="P3_VWC",
            legend_label = 'lukens 28 cm',
            line_color = 'green',
            source=lukens_df)

但我想确保两个图表的 y 轴范围相同,以便图表具有可比性。有没有简单的方法可以做到这一点?

我尝试创建第二个图形以使 y_range 等于第一个图形的 y_range...

vwc_fig = figure(plot_width=1200, plot_height=400, title="Volumetric Water Content",
                x_axis_type="datetime",
                )
vwc_fig2 = figure(plot_width=1200, plot_height=400, y_range=vwc_fig.y_range, title="Volumetric Water Content",
                 x_axis_type="datetime",
                 )

但这没有用。没有出现错误,图表看起来没有什么不同。我还尝试了其他方法,例如手动设置范围,但这也不起作用。比如……

vwc_fig2.yaxis.ticker = [10, 20, 37.4]
vwc_fig2.yaxis.bounds = [10, 37.4]

更改代码或边界会导致我的 y 轴标签一起消失,但仍然没有出现错误。关于如何实现这一目标的任何提示?感谢您的宝贵时间。

【问题讨论】:

  • 共享范围对象是执行此操作的常用方法,因此您需要详细说明“不起作用”的实际含义。有一个错误?在 Python 或浏览器 JS 控制台中?确切的错误信息是什么?还是情节渲染错误?还是根本没有渲染?
  • 出现的(或缺少的)错误已更新。谢谢。
  • 在这种情况下,您确实需要提供一个完整 Minimal Reproducible Example,以便可以直接对其进行适当调查。

标签: python range bokeh figure yaxis


【解决方案1】:

散景的范围由一个元组指定(最小,最大)。所以在你的情况下,我会为两个图设置相同的 y 范围。

从您的示例中可以看出,添加:

vwc_fig = figure(plot_width=1200, plot_height=400, title="Volumetric Water Content",
                 x_axis_type="datetime", y_range=(10, 37.4))
vwc_fig2 = figure(plot_width=1200, plot_height=400, title="Volumetric Water Content", 
                  x_axis_type="datetime", y_range=(10, 37.4))

然后两者应该具有相同的 y 范围。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 2021-10-05
    • 2021-08-09
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    相关资源
    最近更新 更多