user666
user666

Reputation: 5641

Automatic Legend Placement in Bokeh

Does Bokeh have the functionality to automatically position a legend in a plot, similar to Matplotlib?

Upvotes: 6

Views: 1590

Answers (3)

ReinholdN
ReinholdN

Reputation: 562

I found a way to make it automatic for the position at least.

mid = int(df.shape[0]/2)
v1, v2 = df[:mid].sum().sum(), df[mid:].sum().sum()
fig.legend.location = 'top_right' if v1 > v2 else 'top_left'

you can play around with it and add else if statements to specific position it or even do the same for the colours. Also you need to lock the column that you will be plotting, in this case I let it opened in my dataset I did so.

Upvotes: 3

Luke Canavan
Luke Canavan

Reputation: 2137

Yes. Just set the legend.location attribute as one of the enumerable locations (i.e. 'top_left' or 'bottom_right'):

http://docs.bokeh.org/en/latest/docs/reference/models/annotations.html#bokeh.models.annotations.Legend.location

Upvotes: -2

bigreddot
bigreddot

Reputation: 34568

As of Bokeh 0.12.10, Automatic Legend Placement in Bokeh is still an open feature request that has not yet been implemented.

Upvotes: 2

Related Questions