首页 > 解决方案 > Plotly y 轴表现滑稽

问题描述

所以,我的条形图 y 轴一直表现得很有趣。这是图表,

X 是大学列表,而 Y 轴是 0 到 100 之间的值。

取而代之的是一个范围,比如 0 - 100,这些值无处不在。我不明白为什么。这是我的代码:

uni_list = ['Harvard University',
            'California Institute of Technology',
            'Massachusetts Institute of Technology',
            'Stanford University',
            'Princeton University',
            'University of Cambridge',
            'University of Oxford',
            'University of California, Berkeley',
            'Imperial College London',
            'Yale University']
year_list = [2011, 2012, 2013, 2014, 2015, 2016]
int_std = pd.DataFrame(columns=['university_name', 'year', 'income'])
count = 0
print(int_std)
for university in uni_list:
    for year in year_list:
        int_std.loc[count, 'university_name'] = university
        int_std.loc[count, 'year'] = year
        int_std.loc[count, 'income'] = times[(times['university_name'] == university) & (times['year'] == year)]['income'].iloc[0]
        count = count + 1

bar1 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2011].income.values,
              marker = dict(color = 'yellow', line=dict(color='white', width = 1)),
              name = '2011')
bar2 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2012].income.values,
              marker = dict(color = 'orange', line=dict(color='white', width = 1)),
              name = '2012')
bar3 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2013].income.values,
              marker = dict(color = 'green', line=dict(color='white', width = 1)),
              name = '2013')
bar4 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2014].income.values,
              marker = dict(color = 'blue', line=dict(color='white', width = 1)),
              name = '2014')
bar5 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2015].income.values,
              marker = dict(color = 'red', line=dict(color='white', width = 1)),
              name = '2015')
bar6 = go.Bar(x = uni_list,
              y = int_std[int_std['year'] == 2016].income.values,
              marker = dict(color = 'grey', line=dict(color='white', width = 1)),
              name = '2016')
fig3 = go.Figure(data = [bar1, bar2, bar3, bar4, bar5], layout = go.Layout(barmode = 'group'))
py.plot(fig3)

我使用的数据集来自这里:

https://www.kaggle.com/kanncaa1/plotly-tutorial-for-beginners

我注意到我尝试绘制的任何条形图都会出现这个问题。我不知道为什么。非常感谢您的帮助。

标签: pythonplotly

解决方案


推荐阅读