【问题标题】:How to configure bokeh plot to have responsive width and fixed height如何将散景图配置为具有响应宽度和固定高度
【发布时间】:2019-11-23 13:18:49
【问题描述】:

我使用通过组件功能嵌入的散景。

其实我是用的:

plot.sizing_mode = "scale_width"

根据宽度缩放并保持纵横比。但我希望有一个响应宽度,但有一个固定或最大高度。这怎么可能实现?

【问题讨论】:

    标签: python bokeh


    【解决方案1】:

    stretch_bothscale_both 选项。

    正在显示的项目应如何调整自身大小。可能的值是“fixed”、“scale_width”、“scale_height”、“scale_both”和“stretch_both”。

    “stretch_both”元素是完全响应式的(独立于宽度和高度)并且会调整大小以占据所有可用空间,即使这会改变元素的纵横比。这有时被称为由外而内,是桌面应用程序的典型行为。

    ...

    “scale_both”元素会根据可用的宽度和高度响应调整大小,同时保持原始纵横比。

    https://docs.bokeh.org/en/latest/docs/user_guide/layout.html

    【讨论】:

    • 所以也许问题的答案是。就像是。使用 Strech 并限制 css 中的可用高度......我在哪里嵌入了情节?
    • 是的,我认为这就是门票。我做到了,到目前为止它一直有效。如果对您有用,请考虑接受答案!
    • 你能举个例子吗?我尝试了以下方法- p=figure(x_axis_type='datetime', width=1000, height=300, sizing_mode="scale_both") 我也尝试过将其设置为 p.plot.sizing_mode="scale_both" 我是真的不清楚如何以及在哪里正确设置。
    • -update--**** 我明白了- p=figure(x_axis_type='datetime', width=1000, height=300) /n p.sizing_mode="scale_both"
    【解决方案2】:

    您手动设置两个绘图的高度和宽度,并为布局/网格绘图设置 sizing_mode='scale_width',如下(这将设置固定的纵横比并允许您按宽度缩放):

        plot1 = figure(width=1000, height=300)
        # add lines here
    
        plot2 = figure(width=1000, height=100)
        # add lines here
    
        plots = gridplot([[plot1], [plot2]], sizing_mode='scale_width')
        show(plots)
    

    【讨论】:

    • 是的,但这并不能回答问题...响应宽度,固定高度。
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多