Python常用库之三:Matplotlib

导入模块

1 import matplotlib.pyplot as plt
2 import seaborn as sb

绘制条形图

countplot(data:数据集, x:x坐标轴, color:条形图颜色, order:排序)

color_palette():返回一个RGB元组列表

test = pd.read_csv('pokemon.csv')
print(test.shape)
print(test.tail(10))
# value_counts函数统计各序列频率,并降序
generation_order = test['generation_id'].value_counts().index
print(generation_order)
# color_palette 返回一个RGB元组列表
base_color = sb.color_palette()[0]
sb.countplot(data=test, x='generation_id', color=base_color, order=generation_order)
plt.show()

xticks(rotation:旋转度数):更改绘制x轴标签方向(与水平方向的逆时针夹角度数)

yticks(rotation:旋转度数):更改绘制y轴标签方向(与垂直方向的逆时针夹角度数)

1 plt.xticks(rotation=90)
2 plt.yticks(rotation=45)

猜你喜欢

转载自www.cnblogs.com/reaptomorrow-flydream/p/9222125.html