数据分析3 -绘制图
matplotlib plt.plot() # 绘图函数 plt.show() # 显示图像 1.plot函数:绘制折线图 线型linestyle(-,-.,--,..) 点型marker(v,^,s,*,H,+,X,D,O,...) 颜色color(b,g,r,y,k,w,...) plt.plot([0,3,9,15,30],linestyle = ‘-.‘,color = ‘r‘,marker = ‘o‘) 2.常用方法 plt.plot([0,3,9,15,30],linestyle = ‘-.‘,color = ‘r‘,marker = ‘o‘,label="A") plt.plot([1,3,16,23,30],[30,23,13,25,30],label=‘B‘) plt.title("Title") # 标题 plt.xlabel(‘X‘) # x轴名称 plt.ylabel(‘Y‘) # y轴名称 plt.xticks(np.arange(0,30,2)) # x轴刻度 plt.xlim(-0.2,10,2) # x轴范围 plt.legend() # 曲线图例 3.柱状图 data = [12,34,23,54] labels = [‘Jan‘,‘Fed‘,‘Mar‘,‘Apr‘] plt.xticks([0,1,2,3],labels) # 设置x轴刻度 plt.bar([0,1,2,3],data) 4.横向柱状图 data = [12,34,23,54] labels = [‘Jan‘,‘Fed‘,‘Mar‘,‘Apr‘] plt.yticks([0,1,2,3],labels) plt.barh([0,1,2,3],data) 5.饼图 plt.pie([10,20,30,40],labels=list(‘abcd‘),autopct="%.2f%%",explode=[0.1,0,0,0]) plt.axis("equal") plt.show() 6.散点图 import random x = np.random.randn(100) y = np.random.randn(100) plt.scatter(x,y)
相关推荐
flyfor0 2020-11-16
茄肥猫的窝 2020-10-29
kkbb 2020-10-27
gallon00 2020-10-16
aiwozhiai 2020-10-06
HashData0 2020-09-18
GooTal 2020-09-16
qiujiahao 2020-09-15
Dimples 2020-09-15
qiujiahao 2020-09-11
wangquannuaa 2020-08-30
逍遥友 2020-08-21
nxcjh 2020-08-17
CodeAsWind 2020-08-17
BMUranus 2020-08-16
zlfing 2020-08-16
wordmhg 2020-08-16
Cocainebai 2020-08-15
子昊的茶会 2020-08-04