Hi Bryan,
Thank you for the quick reply.
I did pass ‘legend’ keyword to each glyph I use. And I have a legend display on the plot, but I can’t modify the default settings of the legend.
My code structure is like:
# create a plot
p = Figure(plot_height=700, y_range=Range1d(0, 86400))
# configure outline
p.outline_line_color = 'grey'
p.outline_line_alpha = 0.75
# configure x axis
p.x_range = FactorRange()
p.xaxis[0].formatter = DatetimeTickFormatter(formats=dict(
hours=["%Y-%m-%d"],
days=["%Y-%m-%d"],
months=["%Y-%m-%d"],
years=["%Y-%m-%d"],
))
p.legend.location = 'bottom_left'
p.legend.background_fill_alpha = 0.3
p.legend.label_width = 100
p.legend.label_text_font = 'courier'
p.legend.border_line_color = 'white'
p.legend.border_line_alpha = 0.5
source = ColumnDataSource(data=dict(x=[], y=[], fill_color=[], drug_name=[], value=[]))
r = p.circle(x='x', y='y', source=source, fill_color='fill_color', line_color='pink', legend='Medication', size=20, alpha=0.75)
def update(attr, new, old):
source.data = dict(...)
some input widgets
curdoc().add_root(HBox(inputs, p))
Thank you so much!
Caroline
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
On Thu, Jun 23, 2016 at 3:38 PM, Bryan Van de Ven <[email protected]> wrote:
> Since there may be more than one legend, the ".legends" property returns a special kind of list subclass that automatically "broadcasts" all attributes set on it, to all the contents. What it looks like is that you don't have any legends present, i.e that special broadcasting list is empty. In fact that definitely seems to be the case, given the "IndexError: list index out of range" shown below. Normally to get legends you have to pass a "legend" keyword argument to the glyph functions like p.circle() etc.:
>
>
>
> [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#legends](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#legends)
>
>
>
> Or alternatively, have added a Legend manually with .add_layout() on the plot. Otherwise, there is no legend created automatically. Can you share more of your code?
>
>
>
> Bryan
>
>
>
>
> > On Jun 23, 2016, at 5:30 PM, [email protected] wrote:
>
> >
>
> > Hi Bryan,
>
> >
>
> > I'm using py3 and bokeh 0.12 to create an interactive plot. I can't configure the legend using either legend.x or legend().x (where x is one of the attributes). For example, I get the following error messages:
>
> > print(p.legend.label_text_font)
>
> > AttributeError: '_list_attr_splat' object has no attribute 'label_text_font'
>
> >
>
> > print(p.legend().label_text_font)
>
> > TypeError: '_list_attr_splat' object is not callable
>
> >
>
> > print(p.legend[0].label_text_font)
>
> > IndexError: list index out of range
>
> >
>
> > print(p.legends[0].legend.label_text_font)
>
> > AttributeError: 'Figure' object has no attribute 'legends'
>
> >
>
> > May you help me with this?
>
> >
>
> > Thank you so much!
>
> > Caroline
>
> >
>
> > On Monday, January 18, 2016 at 7:08:24 AM UTC-8, Bryan Van de ven wrote:
>
> > Wu,
>
> >
>
> > There may be more than one legend, so the .legends attribute has to return a *list* of legends. But there is often only one legend, so as a convenience the list returned is "splattable", i.e. you can *set* attributes on it, and that attribute will be set on all the items in the list at once (i.e., all the legends, or axes). This is why you can do:
>
> >
>
> > fig.xaxis.title = "foo"
>
> >
>
> > Which is nice. But there is no way to make that work when *getting* attributes (as you are doing). You have to get a particular items from the list, such as
>
> >
>
> > fig.legends[0].legends
>
> >
>
> > Hope that helps,
>
> >
>
> > Bryan
>
> >
>
> >
>
> > > On Jan 17, 2016, at 4:54 AM, [email protected] wrote:
>
> > >
>
> > > I can not access the legends attribute of figure
>
> > >
>
> > > from bokeh.plotting import figure
>
> > >
>
> > > fig = figure(plot_width=1200, plot_height=800)
>
> > > fig.legend
>
> > >
>
> > > gives [<bokeh.models.annotations.Legend object at 0x7f1d3554eb38>]
>
> > >
>
> > > but I can not get the legend content
>
> > >
>
> > > fig.legend.legends
>
> > >
>
> > > gives error: *** AttributeError: '_list_attr_splat' object has no attribute 'legends'
>
> > >
>
> > > from the source code I can see, bokeh.models.annotations.Legend has legends attribute
>
> > >
>
> > > --
>
> > > 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/4334d738-b499-4cd5-ab08-55c9fba8af60%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4334d738-b499-4cd5-ab08-55c9fba8af60%40continuum.io).
>
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
>
> >
>
> >
>
> > --
>
> > 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/d236acd9-2dda-4162-a1c9-fe8686056ba2%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/d236acd9-2dda-4162-a1c9-fe8686056ba2%40continuum.io).
>
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
>
>
>
> --
>
> You received this message because you are subscribed to a topic in the Google Groups "Bokeh Discussion - Public" group.
>
> To unsubscribe from this topic, visit [https://groups.google.com/a/continuum.io/d/topic/bokeh/jlwh_kVv7-g/unsubscribe](https://groups.google.com/a/continuum.io/d/topic/bokeh/jlwh_kVv7-g/unsubscribe).
>
> To unsubscribe from this group and all its topics, 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/728B5D39-378D-45B4-86A7-4AA96E40868F%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/728B5D39-378D-45B4-86A7-4AA96E40868F%40continuum.io).
> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
</details>