2017-01-25 4 views
1

私は線グラフをプロットしようとしているときに空のグラフが表示されています。私はデータフレームを使用しています。私のサンプルcsvには4列あります。パンダのボケ線グラフプロットの問題

import pandas as pd 
df = pd.read_csv('c:\Temp\abc.csv') 
from bokeh.plotting import figure, show, output_file 

x=df.iloc[:,0] 
y=df.iloc[:,1:] 
output_file("sample.html") 
p = figure(plot_width=400, plot_height=400) 
p.line(x,y,line_width=2) 
show(p) 

ただし、Line()を使用してdfを渡すと、グラフを正常に生成できます。

from bokeh.charts import Line 
Line(df) 
output_notebook() 

私は間違いを見つけられません。

答えて

1

複数行をプロットするには、multi_lineを使用する必要があります。リンク:Plotting with Basic Glyphsを参照してください。私は、あなたのx軸がdfの最初の列にあると仮定し、他の3列を3行にします。

import bokeh 
import bokeh.plotting 
df = np.array(
     [[ 1. , 1.1, 1.2, 1.3], 
     [ 2. , 2.1, 2.2, 2.3], 
     [ 3. , 3.1, 3.2, 3.3], 
     [ 4. , 4.1, 4.2, 4.3], 
     [ 5. , 5.1, 5.2, 5.3]]) 
x=df[:,[0]].repeat(df.shape[1]-1,1).T # x axis values are needed for every line 
y=df[:,1:].T 
p = bokeh.plotting.figure(plot_width=400, plot_height=400) 
p.multi_line(list(x),list(y),line_width=2,color=["firebrick", "navy","green"]) 
bokeh.io.output_notebook() # Erase If output is not a jupyter notebook 
bokeh.io.show(p) 

enter image description here

+0

おかげパブロ:私はここに例を提供しています。それは私の問題を解決しました。 – user7329737