我想用Bokeh绘制整个 Pandas DataFrame。即,我正在寻找等效于第三行的Bokeh:
import pandas as pd
income_df = pd.read_csv("income_2013_dollars.csv", sep='\t', thousands=',')
income_df.plot(x="year")
目前是否有办法做到这一点,还是我必须分别传递每个y值?
最佳答案
来自Bokeh项目维护者的说明:此答案是指自从Bokeh中删除以来很久已过时且不推荐使用的API。有关使用现代且完全受支持的Bokeh API创建条形图的信息,请参阅其他问题/答案。
您可能会发现图表示例很有用:
https://github.com/bokeh/bokeh/tree/master/examples/charts
如果您想要条形图,它将是:
from bokeh.charts import Bar
Bar(income_df, notebook=True).show() # assuming the index is corretly set on your df
您可能需要类似的
Line
或TimeSeries
-只需查看示例以了解更多详细信息和更多配置-例如添加标题,标签等。请注意,您可以使用其他输出方法-笔记本,文件或服务器。请参阅此处的文档:
http://docs.bokeh.org/en/latest/docs/user_guide/charts.html#generic-arguments
更新:(很抱歉如何显示输出)。指定图表显示类型的另一种方法是使用
output_notebook()
,output_file("file.html")
,output_server()
方法,然后使用show方法。例如from bokeh.charts import Bar
from bokeh.plotting import output_notebook, show
output_notebook()
bar = Bar(income_df)
show(bar)
但是,您不能执行以下操作
from bokeh.charts import Bar
from bokeh.plotting import output_notebook
output_notebook()
Bar(income_df).show() # WILL GIVE YOU AN ERROR
两种显示方法不同。