2014-10-27 50 views
8

我正在寻找一种方式来创建一个情节像背景虚化的相当于matplotlib次要情节

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

将在matplotlib,然后可以通过ax0ax1解决做包含几个次要情节。有没有办法在Bokeh中做类似的事情?在景examples画廊我只发现单个地块。

+1

怎么样[IRIS Splom(HTTP://bokeh.pydata。 org/docs/gallery/iris_splom.html)在图库中的例子? – wflynny 2014-10-27 21:26:17

+0

感谢@wflynny看起来很有前途。在预览中,它看起来像一个单一的情节。 – greole 2014-10-27 21:33:11

+2

当前'GridPlot'在HTML表格中创建独立的图,所以如果您预览/保存它,您将得到每个单独子图的预览。还计划提供一个布局在单个画布上的网格图,以便预览包含所有的子图。 Bokeh 0.8将是此功能的估计值。 – bigreddot 2014-12-01 17:44:47

回答

7

我认为你可以找到简单的例子是:

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) 

产生输出:

enter image description here