In the following set up, I create a area chart based on the basic example. How do I get the legend for my input automatically or even programatically. For now I get only legend with one item 'a' and the first color.
from bokeh.plotting import *
...
patches([x2 for a in areas], list(areas.values()), color=colors, alpha=0.8,
line_color=None, legend='a', title="hello chart")
legend().orientation = "top_right" # what other options, may here?
show()
What is the format to pass into patches for the legend as value or how can I trigger the legend() to show an item and color for every item in the plot?
I don't have an answer using patches
, but you can use multiple patch
:
from bokeh.plotting import *
...
for a, area in enumerate(areas):
p.patch(x2, areas[area], color=colors[a], legend=area, alpha=0.8, line_color=None)
show()
which shows the legend for each area nicely.
rebeling
I found the following comment in bokeh and stay tuned:
OK, these hand drawn legends are pretty clunky, will be improved in future release
This is working for now:
hold() # stop the curplot()
# and add the legend just next to the data
x, y = 15.5, 0
for i,area in enumerate(areas):
rect([x], [y], color=colors[i], width=0.3, height=400)
text([x], [y], text=area, angle=0, text_font_size="8pt", text_align="center", text_baseline="middle")
y = y + 100
show()
来源:https://stackoverflow.com/questions/25295853/how-to-show-legend-items-of-patches-in-bokeh