This is my plot.
I need to show the legend for the different colors used.
How do I do that?
这是我的情节。我需要显示所用不同颜色的图例。我怎么做?
My code for the 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)
1 个解决方案
#1
2
here is sample bokeh documentation on adding legends
这里是关于添加图例的示例散景文档
You will have to modify as you see fit
您必须根据需要进行修改
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)
the above code will result in the following picture:
上面的代码将产生以下图片:
#1
2
here is sample bokeh documentation on adding legends
这里是关于添加图例的示例散景文档
You will have to modify as you see fit
您必须根据需要进行修改
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)
the above code will result in the following picture:
上面的代码将产生以下图片: