chrstof
November 23, 2016, 3:45pm
1
Hey guys,
I try to plot a ColumnDataSource and set the legend names to the name of the data column, however this fails:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file
from bokeh.layouts import row
import pandas as pd
df = pd.DataFrame(data=None,index = range(0,100))
df['DATA_A'] = 0
df['DATA_B'] = 1
CDS= ColumnDataSource(df)
p1 = figure()
p1.line(x='index', y='DATA_A', source=CDS,line_color='green',legend='bla A')
p1.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend='bla B')
p2 = figure()
p2.line(x='index', y='DATA_A', source=CDS,line_color='green',legend='DATA_A')
p2.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend='DATA_B')
output_file("legend.html")
show(row(p1,p2))
p1 shows the correct legend entries, p2 does not! I assume this is because ‘DATA_A’ and ‘DATA_B’ are column names of CDS.
So how can I set the legend to the column names of CDS?
Thanks for your help!
Bryan
November 27, 2016, 8:56pm
2
The capability to automatically generate legends by grouping the values in a CDS column is a new feature available as of Bokeh 0.12.3 and newer. It's "on" by default, but sometimes it's not what's desired. You can explicitly tell Bokeh that the legend is a value, and not a field:
from bokeh.core.properties import value
p2.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend=value('DATA_B'))
Thanks,
Bryan
···
On Nov 23, 2016, at 9:45 AM, 'chrstof' via Bokeh Discussion - Public <[email protected] > wrote:
Hey guys,
I try to plot a ColumnDataSource and set the legend names to the name of the data column, however this fails:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file
from bokeh.layouts import row
import pandas as pd
df = pd.DataFrame(data=None,index = range(0,100))
df['DATA_A'] = 0
df['DATA_B'] = 1
CDS= ColumnDataSource(df)
p1 = figure()
p1.line(x='index', y='DATA_A', source=CDS,line_color='green',legend='bla A')
p1.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend='bla B')
p2 = figure()
p2.line(x='index', y='DATA_A', source=CDS,line_color='green',legend='DATA_A')
p2.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend='DATA_B')
output_file("legend.html")
show(row(p1,p2))
p1 shows the correct legend entries, p2 does not! I assume this is because 'DATA_A' and 'DATA_B' are column names of CDS.
So how can I set the legend to the column names of CDS?
Thanks for your help!
--
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/c90f681c-51d4-49b0-a8f7-435554a9e3d8%40continuum.io\ .
For more options, visit https://groups.google.com/a/continuum.io/d/optout\ .
chrstof
December 2, 2016, 12:48pm
3
Great, thanks for your help!
···
Am Sonntag, 27. November 2016 21:56:06 UTC+1 schrieb Bryan Van de ven:
The capability to automatically generate legends by grouping the values in a CDS column is a new feature available as of Bokeh 0.12.3 and newer. It’s “on” by default, but sometimes it’s not what’s desired. You can explicitly tell Bokeh that the legend is a value, and not a field:
from bokeh.core.properties import value
p2.line(x='index', y='DATA_B', source=CDS,line_color='blue',legend=value('DATA_B'))
Thanks,
Bryan
On Nov 23, 2016, at 9:45 AM, ‘chrstof’ via Bokeh Discussion - Public [email protected] wrote:
Hey guys,
I try to plot a ColumnDataSource and set the legend names to the name of the data column, however this fails:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file
from bokeh.layouts import row
import pandas as pd
df = pd.DataFrame(data=None,index = range(0,100))
df[‘DATA_A’] = 0
df[‘DATA_B’] = 1
CDS= ColumnDataSource(df)
p1 = figure()
p1.line(x=‘index’, y=‘DATA_A’, source=CDS,line_color=‘green’,legend=‘bla A’)
p1.line(x=‘index’, y=‘DATA_B’, source=CDS,line_color=‘blue’,legend=‘bla B’)
p2 = figure()
p2.line(x=‘index’, y=‘DATA_A’, source=CDS,line_color=‘green’,legend=‘DATA_A’)
p2.line(x=‘index’, y=‘DATA_B’, source=CDS,line_color=‘blue’,legend=‘DATA_B’)
output_file(“legend.html”)
show(row(p1,p2))
p1 shows the correct legend entries, p2 does not! I assume this is because ‘DATA_A’ and ‘DATA_B’ are column names of CDS.
So how can I set the legend to the column names of CDS?
Thanks for your help!
–
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/c90f681c-51d4-49b0-a8f7-435554a9e3d8%40continuum.io .
For more options, visit https://groups.google.com/a/continuum.io/d/optout .