import matplotlib.pyplot as plt import numpy as np from skimage import data fig1 = plt.figure(num='fig1', figsize=(6, 8), dpi=75, facecolor='#FFFFFF', edgecolor='#FF0000')#定义画布的大小及样式 plt.subplot(211)#在2x1画布中第一块区域输出图形 ax1 = fig1.add_subplot(211) ax1.set_title('Scatter Plot1')#子图表的标题 plt.xlabel('x')#设置x轴的标签 plt.ylabel('y')#设置y轴的标签 plt.plot([1,2,3,6],[4,5,8,1],'r-s')#plt.plot(x,y,format_string,**kwargs),x表示x轴,y表示y轴,format_string表示线条的样式 plt.subplot(212)#在2x1画布中第二块区域输出图形 ax1 = fig1.add_subplot(212) ax1.set_title('Function Plot1')#设置标题 plt.xlabel('x')#设置x轴的标签 plt.ylabel('y')#设置y轴的标签 x=np.linspace(-1,1,5) y=2*x+1 plt.plot(x,y,'g-s') plt.show() fig2 = plt.figure(num='fig2', figsize=(12, 9), dpi=75, facecolor='#FFFFFF', edgecolor='#FF0000') plt.xlim(-2,5)#设置x轴的范围 plt.ylim(-2,5)#设置y轴的范围 plt.xticks(np.linspace(-2,5,15,endpoint=True))#设置x轴刻度 plt.yticks(np.linspace(-2,5,10,endpoint=True))#设置y轴刻度 plt.plot(x,y,'g-s') plt.show() fig3=plt.figure(num='fig3',figsize=(9,6),dpi=75,facecolor='#FFFFFF',edgecolor='#FF0000') fig3.suptitle('Scatter Plot1')#图表总标题 plt.xlabel('N')#设置x轴的标签 plt.ylabel('M')#设置y轴的标签 N=[0,1,2,3,4,5,6,7,8] M=[0,1,2,3,4,5,6,7,8] plt.scatter(N,M,c = 'b',marker = 'o')#画散点图 plt.legend('show picture x1 ')#在子图表上设置图标 plt.show() img=data.camera() fig4 = plt.figure(num='fig4', figsize=(12, 9), dpi=75, facecolor='#FFFFFF', edgecolor='#FF0000') plt.subplot(121) h1 = fig4.add_subplot(121) h1.set_title('hist_img')#子图表的标题 plt.xlabel('pixels')#设置x轴的标签 plt.ylabel('num')#设置y轴的标签 arr=img.flatten() n, bins, patches = h1.hist(arr, bins=256, normed=1,edgecolor='None',facecolor='red') plt.subplot(122) h2=fig4.add_subplot(122) h2.set_title('hist')#子图表的标题 plt.xlabel('value')#设置x轴的标签 plt.ylabel('num')#设置y轴的标签 arr2=np.array([1,2,3,4,5,6,7,8,9,11,12,12,12,13,1,21,4,2,5,3,4,8,8,5,5,3,3,5,5,4,4,3,9,8,7,6,12]) n2, bins2, patches2 = h2.hist(arr2, bins=21) print("value_bins:",n2) print("range_bins:",bins2) print("num_bins:",patches2) plt.show()
参考文章:
https://blog.csdn.net/qiurisiyu2016/article/details/80187177