1,安裝Anaconda后,在cmd中,查看Bokeh庫的版本:
conda list
2.將Bokeh更新至1.1.0版本
conda instal bokeh=1.1.0
3.散點圖:
1 def scatter(): 2 x=[1,2,3,4,5] 3 y=[6,7,2,4,5] 4 5 p=figure(plot_width=400,plot_height=400) 6 p.circle(x,y,size=20,color='red',alpha=0.5) 7 show(p)
結果:
4.使用iris數據集,對
"petal_length", "sepal_width"這兩個屬性進行類別的分布顯示。
from bokeh.plotting import figure,show def iris(): from bokeh.sampledata.iris import flowers from bokeh.transform import factor_cmap, factor_mark # print(flowers) # 150*3,屬性:sepal_length sepal_width petal_length petal_width species # 鳶尾花品種及分類標記 SPECIES = ['setosa', 'versicolor', 'virginica'] MARKERS = ['hex', 'circle_x', 'triangle'] # 類別標記 # 畫布 p = figure(title="Iris Morphology", background_fill_color="#fafafa") # title:畫布的命名,第二個參數,背景顏色填充 # 繪圖,(x坐標,y坐標,data_source,marker:標記了,color:顏色填充,) p.scatter("petal_length", "sepal_width", source=flowers, legend="species", fill_alpha=0.4, size=12, marker=factor_mark('species', MARKERS, SPECIES), color=factor_cmap('species', 'Category10_3', SPECIES)) # 取了兩個屬性 p.xaxis.axis_label = 'Petal Length' # 橫坐標描述 p.yaxis.axis_label = 'Sepal Width' # 縱坐標描述 # 顯示 show(p)