matplotlib图像环境基本配置

from matplotlib.pylab import *
import  numpy as np

x=np.linspace(-np.pi,np.pi,256) #构造x序列
c,s=np.cos(x),np.sin(x)  #分别定义函数
#plot(x,c)
#plot(x,s)
#show()


# 图像环境配置 - subplot
'''
subplot(1,1,1)
plot(x,c,color='red',linewidth=1.0,linestyle='-')   # linewidth 线条粗细粒度  #linestyle 线条样式
plot(x,s,color='blue',linewidth=3.0,linestyle='-')
#show()
''' 线条样式参数
 
 
'-'       solid line style  #实线
'--'      dashed line style #虚线
'-.'      dash-dot line style #虚线+点
':'       dotted line style  #点线
'''subplot(2,1,1)plot(x,c,color='red',linewidth=1.0,linestyle='-')plot(x,s,color='blue',linewidth=3.0,linestyle='-')subplot(2,1,2)plot(x,s,color='blue',linewidth=3.0,linestyle='-')show()# 图像环境配置 - xlim ylim 坐标轴的范围xlim(-4.0,4.0)ylim(-4.0,4.0)plot(x,s,color='blue',linewidth=3.0,linestyle='-')show()# 图像环境配置-xticks yticks 坐标轴的范围xticks(np.linspace(-4,4,5,endpoint=True))plot(x,s,color='blue',linewidth=3.0,linestyle='-')show()# 图像环境配置-图例,通过label参数进行控制plot(x,s,color='blue',linewidth=3.0,linestyle='-',label='sin')legend(loc='best')show()''''''bestupper rightupper leftlower leftlower rightrightcenter leftcenter rightlower centerupper centercenter'''# 散点图x=np.random.normal(0,1,1000)y=np.random.normal(0,1,1000)scatter(x,y)xlabel("x axis",fontsize=14,color='red') #x轴标题ylabel("y axis") #y轴标题title("test diagram") #图像标题grid(True) #是否划分为网格#text(0.5,0.5,'haha') # 坐标文字annotate('point',xy=(0.5,0.5),xytext=(3,3),arrowprops=dict(facecolor='red',shrink=0.5)) #箭头指向某个点show()

猜你喜欢

转载自blog.csdn.net/huangqihao723/article/details/80833235