當我嘗試將 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 上運行了你的代碼,它工作正常。
添加回答
舉報
0/150
提交
取消