Plot the whole pandas DataFrame with Bokeh

Anarcho-Chossid picture Anarcho-Chossid · Feb 22, 2015 · Viewed 18.4k times · Source

I would like to plot a whole pandas DataFrame with Bokeh. I.e., I am looking for a Bokeh equivalent of the third line:

import pandas as pd
income_df = pd.read_csv("income_2013_dollars.csv", sep='\t', thousands=',')
income_df.plot(x="year")

Is there currently a way to do that, or do I have to pass each y-value separately?

Answer

birdsarah picture birdsarah · Feb 22, 2015

Note from Bokeh project maintainers: This answer refers to an obsolete and deprecated API was long since removed from Bokeh. For information about creating bar charts with modern and fully supported Bokeh APIs, see other Questions/Answers.


You may find the charts examples useful:

https://github.com/bokeh/bokeh/tree/master/examples/charts

If you wanted a bar chart it would be:

from bokeh.charts import Bar
Bar(income_df, notebook=True).show()  # assuming the index is corretly set on your df

You may want a Line or TimeSeries which work similarly - just checkout the examples for more details and more configuration - like adding titles, labels etc.

Note that you can use other output methods - notebook, file, or server. See the documentation here: http://docs.bokeh.org/en/latest/docs/user_guide/charts.html#generic-arguments

Update: (sorry for the confusion on how to display the output). An alternative way of specifying the display type of the chart is to use the methods output_notebook(), output_file("file.html"), output_server() and then use the show method. For example

from bokeh.charts import Bar
from bokeh.plotting import output_notebook, show
output_notebook()
bar = Bar(income_df)
show(bar)

However, you cannot do the following

from bokeh.charts import Bar
from bokeh.plotting import output_notebook
output_notebook()
Bar(income_df).show()  # WILL GIVE YOU AN ERROR

The two show methods are different.