"line_color" kwarg issue within bokeh.plotting interface using multi_line method

Hi all,

I have written some code that uses the bokeh-server to read-in CSV files from a given folder and uses multi-line plot in conjunction with CheckboxGroup to toggle each CSV file.

I am glad to say I have done this successfully except for one issue: line_color isn’t properly assigning colors when passing in list of lists from ColumnDataSource objects.

The graph is being displayed properly, but the line colors show up as all grey as seen in the image below:

I am creating this plot using primarily this batch of code withing a classmethod:

obj = cls()

obj.source1 = ColumnDataSource(data=dict(xs=, ys=))

obj.source2 = ColumnDataSource(data=dict(xs=, ys=))

obj.source3 = ColumnDataSource(data=dict(xs=, ys=))

fns = get_filenames(path_to_dir, suffix=’.csv’)

obj.toggle = CheckboxGroup(labels=fns, active=[0])

print(obj.toggle)

colors= [’#3498DB’, ‘F1C40F’, ‘#16A085’, ‘#C0392B’]

toolset = “crosshair,pan,reset,resize,save,wheel_zoom”

plot = figure(plot_height=400,

plot_width=800,

tools=toolset,

x_axis_type=“datetime”

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source1,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source2,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source3,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

obj.plot = plot

obj.update_data()

obj.inputs = VBoxForm(

children=[

obj.toggle

]

)

obj.children.append(obj.inputs)

obj.children.append(obj.plot)

return obj

``

xs and ys are list of lists and are being updated using the follow example code:

    df_list = load_csv_to_dflist(path_to_dir, suffix=".csv")

    x1 = x2 = x3 = []

    y1 = y2 = y3 = []

    print(self.toggle.active, "self.toggle")

    for p in self.toggle.active:

        if p == 0:

            DT = df_list[p].Date.tolist()

            x1 = [DT, DT, DT, DT]

            y1 = [df_list[p].C.tolist(),

                  df_list[p].D.tolist(),

                  df_list[p].Cases.tolist(),

                  df_list[p].Deaths.tolist()]

        if p == 1:

            DT = df_list[p].Date.tolist()

            x2 = [DT, DT, DT, DT]

            y2 = [df_list[p].C.tolist(),

                  df_list[p].D.tolist(),

                  df_list[p].Cases.tolist(),

                  df_list[p].Deaths.tolist()]

        if p == 2:

            DT = df_list[p].Date.tolist()

            x3 = [DT, DT, DT, DT]

            y3 = [df_list[p].C.tolist(),

                  df_list[p].D.tolist(),

                  df_list[p].Cases.tolist(),

self.source1.data = dict(xs=x1, ys=y1)

self.source2.data = dict(xs=x2, ys=y2)

self.source3.data = dict(xs=x3, ys=y3)

                  df_list[p].Deaths.tolist()]

``

If you would like to see the full code you can go here: Toggle2_small.py · GitHub

Thanks,

Andy

Wow, solved…
The problem was I didnt have the source.data lines at the end of the update_data() method contain a dictionary of the colors.

This is what was needed:

self.source1.data = dict(xs=x1, ys=y1, colors=[‘red’,‘green’,‘blue’,‘purple’])

self.source2.data = dict(xs=x2, ys=y2, colors=[‘red’,‘green’,‘blue’,‘purple’])

self.source3.data = dict(xs=x3, ys=y3, colors=[‘red’,‘green’,‘blue’,‘purple’])

This stack overflow link helped me out somewhat: python - Bokeh hovertool in multiple_line plot - Stack Overflow

I need to start understanding ColumnDataSource more…

···

On Tuesday, July 28, 2015 at 4:17:24 PM UTC-7, Andrew Joros wrote:

Hi all,

I have written some code that uses the bokeh-server to read-in CSV files from a given folder and uses multi-line plot in conjunction with CheckboxGroup to toggle each CSV file.

I am glad to say I have done this successfully except for one issue: line_color isn’t properly assigning colors when passing in list of lists from ColumnDataSource objects.

The graph is being displayed properly, but the line colors show up as all grey as seen in the image below:

I am creating this plot using primarily this batch of code withing a classmethod:

obj = cls()

obj.source1 = ColumnDataSource(data=dict(xs=, ys=))

obj.source2 = ColumnDataSource(data=dict(xs=, ys=))

obj.source3 = ColumnDataSource(data=dict(xs=, ys=))

fns = get_filenames(path_to_dir, suffix=‘.csv’)

obj.toggle = CheckboxGroup(labels=fns, active=[0])

print(obj.toggle)

colors= [‘#3498DB’, ‘F1C40F’, ‘#16A085’, ‘#C0392B’]

toolset = “crosshair,pan,reset,resize,save,wheel_zoom”

plot = figure(plot_height=400,

plot_width=800,

tools=toolset,

x_axis_type=“datetime”

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source1,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source2,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

plot.multi_line(‘xs’, ‘ys’, source=obj.source3,

line_width=3,

line_color=[‘red’,‘green’,‘blue’,‘purple’]

)

obj.plot = plot

obj.update_data()

obj.inputs = VBoxForm(

children=[

obj.toggle

]

)

obj.children.append(obj.inputs)

obj.children.append(obj.plot)

return obj

``

xs and ys are list of lists and are being updated using the follow example code:

    df_list = load_csv_to_dflist(path_to_dir, suffix=".csv")
    x1 = x2 = x3 = []
    y1 = y2 = y3 = []
    print(self.toggle.active, "self.toggle")
    for p in self.toggle.active:
        if p == 0:
            DT = df_list[p].Date.tolist()
            x1 = [DT, DT, DT, DT]
            y1 = [df_list[p].C.tolist(),
                  df_list[p].D.tolist(),
                  df_list[p].Cases.tolist(),
                  df_list[p].Deaths.tolist()]
        if p == 1:
            DT = df_list[p].Date.tolist()
            x2 = [DT, DT, DT, DT]
            y2 = [df_list[p].C.tolist(),
                  df_list[p].D.tolist(),
                  df_list[p].Cases.tolist(),
                  df_list[p].Deaths.tolist()]
        if p == 2:
            DT = df_list[p].Date.tolist()
            x3 = [DT, DT, DT, DT]
            y3 = [df_list[p].C.tolist(),
                  df_list[p].D.tolist(),
                  df_list[p].Cases.tolist(),

self.source1.data = dict(xs=x1, ys=y1)

self.source2.data = dict(xs=x2, ys=y2)

self.source3.data = dict(xs=x3, ys=y3)

                  df_list[p].Deaths.tolist()]

``

If you would like to see the full code you can go here: https://gist.github.com/ajoros/e80760c3ede0562cd379

Thanks,

Andy

Andrew,

Yes, we no longer support calling glyphs fun tons with "mixed" values, were some are fieldnames (plus a source passed in), and others are literal data lists. There reason is because doing so means necessarily means modifying the source that is passed in, and that's not a "nice" thing to do implicitly (e.g. would be easy to overwrite a column you didn't mean to have overwritten).

There was at some point, a deprecation raised, but unfortunately python does not actually show deprecation warnings by default (you have to run with -Wd command line flag, or take other measures to see deprecations).

BTW if you already have a CDS self.source1, you could just do:

  self.source1.data['colors'] = ['red','green','blue','purple']

CSS is just a thin wrapper around a dictionary that has: i) strings keys, ii) sequences (lists, tuples, arrays) as values, where iii) all the sequences have the *same length*.

Bryan

···

On Jul 28, 2015, at 8:26 PM, Andrew Joros <[email protected]> wrote:

Wow, solved...
The problem was I didnt have the source.data lines at the end of the update_data() method contain a dictionary of the colors.
This is what was needed:
self.source1.data = dict(xs=x1, ys=y1, colors=['red','green','blue','purple'])
self.source2.data = dict(xs=x2, ys=y2, colors=['red','green','blue','purple'])
self.source3.data = dict(xs=x3, ys=y3, colors=['red','green','blue','purple'])

This stack overflow link helped me out somewhat: python - Bokeh hovertool in multiple_line plot - Stack Overflow

I need to start understanding ColumnDataSource more...

On Tuesday, July 28, 2015 at 4:17:24 PM UTC-7, Andrew Joros wrote:
Hi all,

I have written some code that uses the bokeh-server to read-in CSV files from a given folder and uses multi-line plot in conjunction with CheckboxGroup to toggle each CSV file.

I am glad to say I have done this successfully except for one issue: line_color isn't properly assigning colors when passing in list of lists from ColumnDataSource objects.
The graph is being displayed properly, but the line colors show up as all grey as seen in the image below:

I am creating this plot using primarily this batch of code withing a classmethod:
        obj = cls()
        obj.source1 = ColumnDataSource(data=dict(xs=, ys=))
        obj.source2 = ColumnDataSource(data=dict(xs=, ys=))
        obj.source3 = ColumnDataSource(data=dict(xs=, ys=))

        fns = get_filenames(path_to_dir, suffix='.csv')
        obj.toggle = CheckboxGroup(labels=fns, active=[0])
        print(obj.toggle)

# colors= ['#3498DB', 'F1C40F', '#16A085', '#C0392B']
        toolset = "crosshair,pan,reset,resize,save,wheel_zoom"
        plot = figure(plot_height=400,
                      plot_width=800,
                      tools=toolset,
                      x_axis_type="datetime"
                      )
        plot.multi_line('xs', 'ys', source=obj.source1,
                  line_width=3,
                  line_color=['red','green','blue','purple']
                  )
        plot.multi_line('xs', 'ys', source=obj.source2,
                  line_width=3,
                  line_color=['red','green','blue','purple']
                  )
        plot.multi_line('xs', 'ys', source=obj.source3,
                  line_width=3,
                  line_color=['red','green','blue','purple']
                  )

        obj.plot = plot
        obj.update_data()

        obj.inputs = VBoxForm(
            children=[
                obj.toggle
            ]
        )

        obj.children.append(obj.inputs)
        obj.children.append(obj.plot)
        return obj

xs and ys are list of lists and are being updated using the follow example code:
        df_list = load_csv_to_dflist(path_to_dir, suffix=".csv")
        x1 = x2 = x3 =
        y1 = y2 = y3 =
        print(self.toggle.active, "self.toggle")

        for p in self.toggle.active:
            if p == 0:
                DT = df_list[p].Date.tolist()
                x1 = [DT, DT, DT, DT]
                y1 = [df_list[p].C.tolist(),
                      df_list[p].D.tolist(),
                      df_list[p].Cases.tolist(),
                      df_list[p].Deaths.tolist()]
            if p == 1:
                DT = df_list[p].Date.tolist()
                x2 = [DT, DT, DT, DT]
                y2 = [df_list[p].C.tolist(),
                      df_list[p].D.tolist(),
                      df_list[p].Cases.tolist(),
                      df_list[p].Deaths.tolist()]
            if p == 2:
                DT = df_list[p].Date.tolist()
                x3 = [DT, DT, DT, DT]
                y3 = [df_list[p].C.tolist(),
                      df_list[p].D.tolist(),
                      df_list[p].Cases.tolist(),
                      df_list[p].Deaths.tolist()]
        self.source1.data = dict(xs=x1, ys=y1)
        self.source2.data = dict(xs=x2, ys=y2)
        self.source3.data = dict(xs=x3, ys=y3)

If you would like to see the full code you can go here: https://gist.github.com/ajoros/e80760c3ede0562cd379

Thanks,

Andy

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/bf12af23-4ee9-47ae-9f3a-e2884727fcf9%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.