Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 博克';s相当于matplotlib子批次_Python_Matplotlib_Bokeh - Fatal编程技术网

Python 博克';s相当于matplotlib子批次

Python 博克';s相当于matplotlib子批次,python,matplotlib,bokeh,Python,Matplotlib,Bokeh,我正在寻找一种方法来创建一个包含多个子地块的地块,如 fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True) 将在matplotlib中执行,然后可以通过ax0和ax1对其进行寻址。在博克有没有类似的方法?在博克画廊里,我只找到了一幅图。我认为你能找到的更简单的例子是: import numpy as np import bokeh.plotting as bk_plotting import bokeh.models as bk_models

我正在寻找一种方法来创建一个包含多个子地块的地块,如

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

将在matplotlib中执行,然后可以通过
ax0
ax1
对其进行寻址。在博克有没有类似的方法?在博克画廊里,我只找到了一幅图。

我认为你能找到的更简单的例子是:

import numpy as 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)
这将生成输出:


图库中的示例如何?谢谢@wflynny,这看起来很有希望。在预览中,它看起来就像一个单独的绘图。当前的
GridPlot
在HTML表中创建独立的绘图,因此,如果您预览/保存它,您将获得每个单独子绘图的预览。也有计划提供一个网格图,在一个画布上进行布局,以便预览包含所有子地块。Bokeh 0.8将是该特性的估计值。