Hello!
I have a plot I’m fairly happy with. But I’d like the legend to be located outside the plot area.
The documentation says that " To position a legend outside the central area, use the add_layout
method of a plot. This requires creating the Legend object directly".
The reason I have not created the legend directly, e.g.,
legend = Legend(items=('var1',[var1]),
is that the exact variables (number of them and the content) change.
I’m creating the plot by:
for i in range(0, N_sites):
site = sites[i]
fullname = site_fullname(site)
fig.circle(x=df['t'], y=df['value_'+site],
fill_color = colours[i],
size=10, alpha=0.7,
visible = False,
legend_label = fullname)
So my thought is that I need to (1) create the figure, (2) extract the information from the figure needed to make the legend, and then (3) re-create the legend explicitly so it can be re-located outside the plot.
This seems awkward and inefficient. More importantly, I’m not sure how to do this.
Maybe I have to write a less flexible version of the code that does only a set of variables and values, but that’s a big compromise for the sake of moving the legend.
Advice on the best approach would be greatly appreciated!