简体   繁体   English

用熊猫绘制散景线图的问题

[英]Issue with plotting bokeh line graph with pandas

I am getting blank graph when I am trying to plot line graph.当我尝试绘制折线图时,我得到了空白图。 I am using dataframe.我正在使用数据框。 My sample csv has 4 columns.我的示例 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)

However when I use Line() and pass df, I am able to generate graph successfully.但是,当我使用 Line() 并传递 df 时,我能够成功生成图形。

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

I am not able to find out what mistake I am making.我无法找出我犯了什么错误。

You will have to use multi_line to plot multiple lines.您将不得不使用multi_line来绘制多条线。 See the link:Plotting with Basic Glyphs .请参阅链接:使用基本字形绘图 I assume your x axis is in the first column of df, and you want the other 3 columns as three lines.我假设您的 x 轴在 df 的第一列中,而您希望其他 3 列作为三行。 I provide an example here:我在这里提供一个例子:

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM