下面是使用CDS(列数据结构)时出错的代码。你知道吗
有什么想法吗?你知道吗
#Plotting flower species
#Importing libraries
from bokeh.plotting import figure
from bokeh.io import output_file, show
from bokeh.sampledata.iris import flowers
from bokeh.models import Range1d, PanTool, ResetTool, HoverTool, ColumnDataSource, LabelSet
colormap={'setosa':'red','versicolor':'green','virginica':'blue'}
flowers['color']=[colormap[x] for x in flowers['species']]
setosa=ColumnDataSource(flowers[flowers["species"]=="setosa"])
versicolor=ColumnDataSource(flowers[flowers["species"]=="versicolor"])
virginica=ColumnDataSource(flowers[flowers["species"]=="virginica"])
#Define the output file path
output_file("iris.html")
#Create the figure object
f=figure()
#adding glyphs
f.circle(x="petal_length", y="petal_width",
size=[i*4 for i in setosa.data["sepal_width"]],
fill_alpha=0.2,color="color",line_dash=[5,3],legend='Setosa',source=setosa)
f.circle(x="petal_length", y="petal_width",
size=[i*4 for i in setosa.data["sepal_width"]],
fill_alpha=0.2,color="color",line_dash=[5,3],legend='Versicolor',source=versicolor)
f.circle(x="petal_length", y="petal_width",
size=[i*4 for i in setosa.data["sepal_width"]],
fill_alpha=0.2,color="color",line_dash=[5,3],legend='Virginica',source=virginica)
#Save and show the figure
show(f)
您需要将
size
列放在数据帧中:所以它是在
ColumnDataSource
中,你稍后再做。然后将列名与glyph函数一起使用:不过,您也可以只传递数据帧,然后会自动为您创建一张CD,这更简单。以下是完整版本:
相关问题 更多 >
编程相关推荐