2014-10-27 24 views
8

Tôi đang tìm kiếm một cách để tạo ra một âm mưu có chứa nhiều ô phụ nhưBokeh của tương đương với Matplotlib subplots

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

sẽ làm gì trong matplotlib, mà sau đó có thể được giải quyết bằng ax0ax1. Có cách nào để làm điều gì đó tương tự trong Bokeh không? Trong bộ sưu tập bokeh examples tôi chỉ tìm thấy các ô đơn lẻ.

+1

gì về [Iris Splom] (http: //bokeh.pydata. org/docs/gallery/iris_splom.html) ví dụ trong thư viện? – wflynny

+0

Cảm ơn @ wflynny có vẻ đầy hứa hẹn. Trong bản xem trước nó chỉ trông giống như một cốt truyện duy nhất. – greole

+2

'GridPlot' hiện tại tạo ra các ô độc lập trong một bảng HTML, vì vậy nếu bạn xem trước/lưu vào nó, bạn sẽ nhận được bản xem trước cho từng tiểu vùng riêng lẻ. Có những kế hoạch cũng cung cấp một ô lưới được bố trí trên một khung hình duy nhất, để một bản xem trước sẽ chứa tất cả các ô con. Bokeh 0.8 sẽ là ước tính cho tính năng này. – bigreddot

Trả lời

7

Tôi nghĩ rằng ví dụ đơn giản hơn bạn có thể tìm thấy là:

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) 

nào tạo ra kết quả:

enter image description here

Các vấn đề liên quan