簡體   English   中英

如何在散景散點圖中顯示不同顏色的圖例?

[英]How do I show legend for different colors in bokeh scatter 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)

這里是關於添加圖例的示例散景文檔

您必須根據需要進行修改

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)

以上代碼將產生以下圖片:

散點圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM