为了账号安全,请及时绑定邮箱和手机立即绑定

Matplotlib 上的未知属性刻度错误

Matplotlib 上的未知属性刻度错误

饮歌长啸 2023-08-22 17:08:35
当我尝试将 x 轴的标签更改为 的标签时,我遇到了错误ages_x。目前,它是x_indexes,即 的长度ages_x。这是我的代码:import numpy as npfrom matplotlib import pyplot as pltplt.style.use('fivethirtyeight')ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]x_indexes=np.arange(len(ages_x))width= 0.25dev_y = [38496, 42000, 46752, 49320, 53200, 56000, 62316, 64928, 67317, 68748, 73752]plt.bar(x_indexes, dev_y, width=width, color= '#444444', label= 'All Devs')py_dev_y = [45372, 48876, 53850, 57287, 63016, 65998, 70003, 70000, 71496, 75370, 83640]plt.bar(x_indexes - width, py_dev_y, width=width,  label= 'Python')js_dev_y = [37810, 43515, 46823, 49293, 53437, 56373, 62375, 66674, 68745, 68746, 74583]plt.bar(x_indexes + width, js_dev_y, width=width,  label= 'JavaScript')plt.title('Median Salary (USD) by Age')plt.xlabel('Ages')plt.ylabel('Median Salary (USD)')plt.legend()plt.xticks(ticks=x_indexes, labels= ages_x)plt.tight_layout()plt.show()
查看完整描述

1 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

我认为您使用的是旧版本的 Matplotlib

更新到较新的版本,您的代码应该可以正常运行。我刚刚在 matplotlib 3.3.2 上运行了你的代码,它工作正常。



查看完整回答
反对 回复 2023-08-22
  • 1 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信