0
我正在尝试使用python制作散点图,它显示了逐年的基础上的联盟位置和新秀/资深球队信息。 我希望在那里有点列,每年一列,每个位置一个点,其中点的颜色取决于他们是新手还是老手。这散景散点图为什么不显示任何内容?
我有这段代码,但它似乎没有显示任何数据。为什么?
from bokeh.charts import Scatter, show, output_file
from bokeh.models import Range1d
#from vdata.data import get_schools
from collections import OrderedDict
def get_data(years):
schools = get_schools(['raw_data/2015-teams.yaml'], [2015])
d = OrderedDict()
d['rookie'] = []
d['veteran'] = []
for s in schools:
for year in years:
rookie = s.data[year]['rookie']
league_position = s.data[year]['league']
if rookie:
d['rookie'].append((year, league_position))
else:
d['veteran'].append((year, league_position))
return d
data = OrderedDict([('rookie', [(2015, 14), (2015, 26), (2015, 47), (2015, 41), (2015, 24), (2015, 45), (2015, 35), (2015, 46), (2015, 21), (2015, 47), (2015, 5), (2015, 31), (2015, 28), (2015, 30), (2015, 18)]), ('veteran', [(2015, 13), (2015, 27), (2015, 42), (2015, 18), (2015, 39), (2015, 34), (2015, 22), (2015, 2), (2015, 3), (2015, 43), (2015, 8), (2015, 40), (2015, 1), (2015, 29), (2015, 4), (2015, 18), (2015, 44), (2015, 7), (2015, 23), (2015, 16), (2015, 32), (2015, 6), (2015, 37), (2015, 25), (2015, 11), (2015, 38), (2015, 17), (2015, 12), (2015, 15)])])
def league_rookie(d):
scatter = Scatter(d, title='League positions and rookie values', legend=True, ylabel='League Position', xlabel='Year', width=1000, height=600, y_range=Range1d(60, 0))
output_file('visuals/html/league_rookie.html')
show(scatter)
if __name__ == '__main__':
#data = get_data([2015])
league_rookie(data)
我觉得这不是使用Scatter情节的好方法,但我不知道该怎么做。
你是对的。我期望的图是一个垂直列的点(至少在第一年)。 – blueteeth