如何在Bokeh中显示补丁图例项
在下面的设置中,我根据基本示例创建了一个区域图。我想知道怎么才能自动或通过编程的方式获取我的输入的图例。目前我只得到了一个包含“a”和第一个颜色的图例。
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()
我应该以什么格式传递给图例的补丁,或者我该如何触发legend()来显示图中每个项目的图例和颜色呢?
2 个回答
2
我没有关于使用 patches
的答案,不过你可以使用多个 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()
这样可以很好地显示每个区域的图例。
2
我在bokeh中发现了以下评论,大家可以关注一下:
好的,这些手绘的图例看起来有点笨重,未来会进行改进
现在这个是可以用的:
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()