import matplotlib
.pyplot
as plt
x
=list(range(0,100))
y
=[pow(i
,2) for i
in x
]
z
=[2.5*i
for i
in x
]
m
=[4*i
for i
in x
]
n
=[10*i
for i
in x
]
#坐标轴长度设置(放在前面用于全局)
plt
.axis([0,100,0,800])
#分割子区域
plt
.subplot(1,2,1)
#绘制散点图
plt
.scatter(x
,y
,c
=y
,cmap
=plt
.cm
.Reds
)#颜色传递给c,这里设置渐变,坐标点y越大,颜色越深
plt
.ylabel('ylabel')
plt
.grid(True
)#绘制网格
#绘制线
plt
.subplot(1,2,2)
plt
.plot(x
,z
,'bo-',x
,m
,"y-.")#添加曲线选项
plt
.xlabel("X轴",fontproperties
='SimHei',fontsize
=14)#使用中文
plt
.text(70,284,'y=4x',fontproperties
='SimHei',fontsize
=14)
#添加箭头图标
plt
.annotate(r
'$y=2.5x$', xytext
=(90,32),fontproperties
='SimHei',fontsize
=14,xy
=(53,130), arrowprops
=dict(facecolor
="blue",shrink
=0.1,width
=2))
#保存
plt
.savefig('C://Users/administrator/Desktop/test.png',dpi
=800)#先保存在展示,dpi代表保存质量
plt
.show()
结果展示
转载请注明原文地址: https://yun.8miu.com/read-134769.html