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)
2
  • 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? Commented Mar 1, 2017 at 20:35
  • 1
    Thanks for the comment. Using multi_line solved the issue. stackoverflow.com/questions/31520951/… Commented Mar 2, 2017 at 2:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.