微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Matplotlib,条形图 xticks

如何解决Matplotlib,条形图 xticks

enter image description here

这是代码,出于某种原因,条形图显示了六个值中前 5 个的 y 值。第六个国家总是显示值 0,这与数据不正确。

def gdp_comp(year):
    labels = list(df[df.Year == year]['Country'])
    fig,ax = plt.subplots()
    plt.bar(range(len(df[df.Year == year]['GDP'])),df[df.Year == year]['GDP'])
    plt.ylabel('GDP (e+10)')
    plt.xlabel('Countries')
    ax.set_xticks(range(len(df[df.Year == year]['GDP'])))
    ax.set_xticklabels(labels,rotation='vertical')
    plt.title("Countries Comparison Of GDP (e+10) in {}".format(str(year)))
    plt.show()

gdp_comp(2005)

我怎样才能让它绘制第六个国家的图表?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。