1

In bokeh line chart, is there a way to set the color of the line based on a dataframe column? I am trying the following but it doesn't work. The chart doesn't show up if i use the color argument as shown below. If I remove that it shows up.

import pandas as pd
from bokeh.io import  show
from bokeh.plotting import figure
from bokeh.models import NumeralTickFormatter, HoverTool

data = pd.read_csv('C:\\Users\\asde\\Desktop\\Python\\bok\\StateNames.csv',thousands=',',index_col='Id')

#data1 = data[(data.Name == 'Mary')& (data.State == 'AZ')]

data.apply(lambda x: pd.to_numeric(x, errors='ignore'))
data2 = data[(data.Year >= 2010) & (data.Year <= 2014)& (data.State == 'AZ')]
data2.head()
p = figure()
#p.line(x=data1['Year'],y=data1['Count'])
p.line(x=data2['Year'],y=data2['Count'],***color = data2['Name']***)
p.xaxis[0].formatter = NumeralTickFormatter(format='0000')
show(p)
  • 1
    What are the dimensions of data2['Year'], data2['Count'] ? I assume you are interested in plotting more than one line. In that case you should use `multi_line` instead of `line`. and then each line with one color right? – Pablo Reyes Mar 01 '17 at 20:35
  • 1
    Thanks for the comment. Using multi_line solved the issue. http://stackoverflow.com/questions/31520951/plotting-multiple-lines-with-bokeh-and-pandas – user7632376 Mar 02 '17 at 02:12

0 Answers0