【问题标题】:how to show legend items of patches in bokeh如何在散景中显示补丁的图例项
【发布时间】:2014-08-13 20:48:22
【问题描述】:

在下面的设置中,我根据基本示例创建了一个面积图。如何自动甚至以编程方式获取输入的图例。现在我只得到一个带有一个项目“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() 来显示图中每个项目的项目和颜色?

【问题讨论】:

    标签: python legend bokeh legend-properties


    【解决方案1】:

    我没有使用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】:

      我在散景中发现了以下评论,敬请期待:

      好的,这些手绘图例很笨拙,会在以后的版本中改进

      这暂时有效:

      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()
      

      【讨论】:

      • 这方面有什么更新吗?我正在寻找类似的东西。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多