Matplotlib bar column chart x-axis is not in order and rotate x-axis text display angle

Set to rotate 90 degrees:

plt.xticks(rotation=90,fontsize=13)

Adjust the order:

plt.xticks(range(len(x)), x)

plt.bar(range(len(x)), y, color = 'g')

Example code:

# 设置数据
x = np.array(top10['景点名称'])
y = np.array(top10['综合得分'])
print(x, y)
plt.xticks(range(len(x)), x)
# 绘图
plt.bar(range(len(x)), y, color = 'g')
plt.xlabel('景点名称', fontsize=16)
plt.xticks(rotation=90,fontsize=13)
plt.ylabel('综合得分', fontsize=16)
plt.title('综合得分前十景点', fontsize=18)
plt.savefig('./image/综合得分前十景点.png')
plt.show()

 

Published 314 original articles · 22 praises · 20,000+ views

Guess you like

Origin blog.csdn.net/qq_39451578/article/details/105436953