柱状图
如下表
ID | age | score |
---|---|---|
1 | 16 | 80 |
2 | 15 | 96 |
3 | 18 | 88 |
4 | 16 | 75 |
5 | 23 | 90 |
6 | 12 | 65 |
场景1
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("D:/python_test/shaixuan.xls")
print(df)
df = df.sort_values(by='score')
df.plot.bar(x='age',y='score')
plt.show()
无标题.png
场景2
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("D:/python_test/shaixuan.xls")
print(df)
df = df.sort_values(by='score')
#df.plot.bar(x='age',y='score',color='orange',title='student score')
#定义x,y轴
plt.bar(df.age, df.score,color='orange')
#定义x轴名字角度
plt.xticks(df.age,rotation='60')
#定义x,y轴名称
plt.xlabel('age')
plt.ylabel('score')
plt.title('student score')
plt.tight_layout()
plt.show()
plt.show()
Figure_1.png
网友评论