Line legends from ColumnDatasource

Hello again :slight_smile:
Is there an open issue about legends from ColumDataSource? I am trying to create the legends from a graph using the legend option in the line. I iterate over the columns of my datasource adding a line for each column.
The issue is that when I pass strings(?) to the legend i get some weird amount of legends formatted as numbers.

Example bellow: strings

colors = Category10[len(cds.data)]
p = figure(plot_height=1024, plot_width=1400, name="mainGraph")
for idx, column in enumerate(cds.data):
    if column != 'Time' and column != 'index':
        l = p.line('Time',column, legend=column, source=cds, line_color=colors[idx])
        lines.append(l)

``

But if I use a number (converted to a string it seems to work fine): Numbers
colors = Category10[len(cds.data)]
p = figure(plot_height=1024, plot_width=1400, name=“mainGraph”)
for idx, column in enumerate(cds.data):
if column != ‘Time’ and column != ‘index’:
l = p.line(‘Time’,column, legend=str(idx), source=cds, line_color=colors[idx])

``

Cheers!

Hey Juliano,

In the first example you’ve passed a string containing a column name from the column data source to the legend parameter. Since you are using a column data source, Bokeh associates your string input with the corresponding values in the column data source and creates a legend entry for each value in that column. This behavior is consistent with the other parameters.

To get the legend to display the column name instead, pass a single element list containing the string to the legend parameter. In your example changing legend=column to legend=[column] should do the trick.

···

On Tue, Feb 14, 2017 at 1:59 PM, Juliano Franz [email protected] wrote:

Hello again :slight_smile:
Is there an open issue about legends from ColumDataSource? I am trying to create the legends from a graph using the legend option in the line. I iterate over the columns of my datasource adding a line for each column.
The issue is that when I pass strings(?) to the legend i get some weird amount of legends formatted as numbers.

Example bellow: strings

colors = Category10[len(cds.data)]
p = figure(plot_height=1024, plot_width=1400, name="mainGraph")
for idx, column in enumerate(cds.data):
    if column != 'Time' and column != 'index':
        l = p.line('Time',column, legend=column, source=cds, line_color=colors[idx])
        lines.append(l)

``

But if I use a number (converted to a string it seems to work fine): Numbers
colors = Category10[len(cds.data)]
p = figure(plot_height=1024, plot_width=1400, name=“mainGraph”)
for idx, column in enumerate(cds.data):
if column != ‘Time’ and column != ‘index’:
l = p.line(‘Time’,column, legend=str(idx), source=cds, line_color=colors[idx])

``

Cheers!

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/14e19174-3efa-410b-ba96-192aefddbc0b%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.