Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic Legend Placement in Bokeh

Tags:

python

bokeh

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

like image 967
user666 Avatar asked Nov 19 '22 21:11

user666


2 Answers

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

like image 116
bigreddot Avatar answered Nov 22 '22 11:11

bigreddot


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.

like image 41
ReinholdN Avatar answered Nov 22 '22 09:11

ReinholdN