sách gpt4 ai đã đi

python - Bokeh 相当于 matplotlib subplots

In lại Tác giả: Space Dog 更新时间:2023-10-29 20:58:45 26 4
mua khóa gpt4 Nike

我正在寻找一种方法来创建一个包含多个子图的绘图

fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)

会在 matplotlib 中执行,然后可以通过 ax0trục1 来解决。有没有办法在 Bokeh 中做类似的事情?在 Bokeh 中 examples图库我只找到了单个地 block 。

1 Câu trả lời

我认为您可以找到的更简单的示例是:

nhập numpy dưới dạng np
import bokeh.plotting as bk_plotting
import bokeh.models as bk_models

# for the ipython notebook
bk_plotting.output_notebook()

# a random dataset
data = bk_models.ColumnDataSource(data=dict(x=np.arange(10),
y1=np.random.randn(10),
y2=np.random.randn(10)))

# defining the range (I tried with start and end instead of sources and couldn't make it work)
x_range = bk_models.DataRange1d(sources=[data.columns('x')])
y_range = bk_models.DataRange1d(sources=[data.columns('y1', 'y2')])

# create the first plot, and add a the line plot of the column y1
p1 = bk_models.Plot(x_range=x_range,
y_range=y_range,
title="",
min_border=2,
plot_width=250,
plot_height=250)
p1.add_glyph(data,
bk_models.glyphs.Line(x='x',
y='y1',
line_color='black',
line_width=2))

# add the axes
xaxis = bk_models.LinearAxis()
p1.add_layout(xaxis, 'below')
yaxis = bk_models.LinearAxis()
p1.add_layout(yaxis, 'left')

# add the grid
p1.add_layout(bk_models.Grid(dimension=1, ticker=xaxis.ticker))
p1.add_layout(bk_models.Grid(dimension=0, ticker=yaxis.ticker))

# add the tools
p1.add_tools(bk_models.PreviewSaveTool())

# create the second plot, and add a the line plot of the column y2
p2 = bk_models.Plot(x_range=x_range,
y_range=y_range,
title="",
min_border=2,
plot_width=250,
plot_height=250)
p2.add_glyph(data,
bk_models.glyphs.Line(x='x',
y='y2',
line_color='black',
line_width=2))



# add the x axis
xaxis = bk_models.LinearAxis()
p2.add_layout(xaxis, 'below')

# add the grid
p2.add_layout(bk_models.Grid(dimension=1, ticker=xaxis.ticker))
p2.add_layout(bk_models.Grid(dimension=0, ticker=yaxis.ticker))

# add the tools again (it's only displayed if added to each chart)
p2.add_tools(bk_models.PreviewSaveTool())

# display both
gp = bk_plotting.GridPlot(children=[[p1, p2]])
bk_plotting.show(gp)

生成输出:

nhập mô tả hình ảnh ở đây

关于python - Bokeh 相当于 matplotlib subplots,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26596901/

26 4 0
Bài viết được đề xuất: python - 使用 ArcGIS 安装的 Python 2.7 安装 pip
Bài viết được đề xuất: c++ - MSBuild BeforeBuild 步骤
Bài viết được đề xuất: C# LINQ to Entities 无法识别方法 'Boolean'
Bài viết được đề xuất: c++ - 如何使用颜色将 QPlainTextEdit 内容渲染到 QPixmap?
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com