how to show legend items of patches in bokeh

非 Y 不嫁゛ 提交于 2019-12-02 08:12:51

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!