【问题标题】:How do I show legend for different colors in bokeh scatter plot?如何在散景散点图中显示不同颜色的图例?
【发布时间】:2015-08-05 14:39:14
【问题描述】:

这是我的plot
我需要显示所用不同颜色的图例。
我该怎么做?

我的剧情代码:

def mscatter(p, x, y, c,typestr,source):
    p.scatter(x, y, marker=typestr,
            line_color="#6666ee", fill_color=c, fill_alpha=0.5, size=y*1.5,source = source)

p = figure(title="CGPA of 4th year students",tools=[hover])
mscatter(p, xdata, ydata, colors,"circle",source)
show(p)

【问题讨论】:

标签: python python-3.x plot legend bokeh


【解决方案1】:

这是adding legends上的示例散景文档

您必须根据需要进行修改

from collections import OrderedDict
from bokeh.charts import Scatter, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames of (x, y) tuples are valid inputs)
xyvalues = OrderedDict()
xyvalues['python'] = [(1, 2), (3, 3), (4, 7), (5, 5), (8, 26)]
xyvalues['pypy'] = [(1, 12), (2, 23), (4, 47), (5, 15), (8, 46)]
xyvalues['jython'] = [(1, 22), (2, 43), (4, 10), (6, 25), (8, 26)]

scatter = Scatter(xyvalues, title="Scatter", legend="top_left", ylabel='Languages')

output_file('scatter.html')
show(scatter)

上面的代码会产生如下图:

【讨论】:

  • 是的,但这似乎不适用于散点图。在这里,只有 3 条线要绘制,所以 3 条曲线用于线条语句,3 条曲线用于图例。我的要求类似于为虹膜图绘制图例。虹膜图有 3 种不同的颜色,所以我需要 3 种颜色的图例及其描述。
猜你喜欢
  • 2020-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 2021-10-29
相关资源
最近更新 更多