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