I am trying to create a chart with several lines, but the data I use usually has a long form:
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0] y0 = [i**2 for i in x] y1 = [10**i for i in x] y2 = [10**(i**2) for i in x] df = pandas.DataFrame(data=[x,y0,y1,y2]).T df.columns = ['x','y0','y1','y2'] df2 = pd.concat([df.iloc[0:,1],df.iloc[0:,2],df.iloc[0:,3]], axis=0, keys = ['a','b','c']).reset_index() df2.columns = ['grp','x','y'] df2 +----+-----+---+----------+ | | grp | x | y | +----+-----+---+----------+ | 0 | a | 0 | 0.01 | | 1 | a | 1 | 0.25 | | 2 | a | 2 | 1.00 | | 3 | a | 3 | 2.25 | | 4 | a | 4 | 4.00 | | 5 | a | 5 | 6.25 | | 6 | a | 6 | 9.00 | | 7 | b | 0 | 1.26 | | 8 | b | 1 | 3.16 | | 9 | b | 2 | 10.00 | | 10 | b | 3 | 31.62 | | 11 | b | 4 | 100.00 | | 12 | b | 5 | 316.23 | | 13 | b | 6 | 1,000.00 | +----+-----+---+----------+ cd_df2 = ColumnDataSource(df2)
That is, I will have βgroupsβ, where x, y pairs for each group are listed on several lines.
Below are all 3 lines, but they are all displayed as gray. Setting color = 'grp' does not define a color for each value in the grp field in the column data source
f = figure(tools="save",y_axis_type="log", y_range=[0.001, 10**11], title="log axis example",x_axis_label='sections', y_axis_label= 'particles') f.line('x','y', line_color = 'grp', source = cd_df2)
How can I achieve this in bokeh.plotting or bokeh.models api (want to avoid high-level diagrams in order to better understand the library)? I am open to other suggestions that allow you to explicitly not call f.line () once for each line and individually set the color (I can have 10 + lines, and that will be tedious).