How to configure bokeh plot to have responsive width and fixed height

百般思念 提交于 2021-02-07 18:16:36

问题


I use bokeh embedded via the components function.

Acutally I use :

plot.sizing_mode = "scale_width"

Which scales according to the width and maintains the aspect ratio. But I would like to have a responsive width but a fixed or maximum height. How is that possible to achieve?


回答1:


There are stretch_both and scale_both options.

How the item being displayed should size itself. Possible values are "fixed", "scale_width", "scale_height", "scale_both", and "stretch_both".

"stretch_both" elements are completely responsive (independently in width and height) and will resize to occupy all available space, even if this changes the aspect ratio of the element. This is sometimes called outside-in, and is a typical behavior for desktop applications.

...

"scale_both" elements will responsively resize to for both the width and height available, while maintaining the original aspect ratio.

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




回答2:


You manually set the height and width for the two plots, and set sizing_mode='scale_width' for the layout/gridplot, as follows (this will set a fixed aspect ratio and allow you to scale by 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)


来源:https://stackoverflow.com/questions/46526446/how-to-configure-bokeh-plot-to-have-responsive-width-and-fixed-height

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