1图片布局
1.画布大小 ——(宽,高)英寸 #A4(21cm,29.7cm)约7英寸,还要减去页边距
fig =plt.figure(figsize = (4,7))
2.画图——纸的形状决定图的形状
2.1 不能控制图的形状)
ax= fig.add_subplot() #无参数默认一张图
ax= plt.subplot()
#eg.
ax= fig.add_subplot(2,3,1) #横排列——2行三列子图第一个 (231)
2.2 可设置图的比例与位置)
ax3 = fig.add_axes([x原点位置,y原点位置,宽度,高度]) #比例(占画布figsize的)
#eg.
ax31 = fig.add_axes(0.1,0.1,0.8,0.3) #自己计算好图的分布比例
ax32 = fig.add_axes([0.1,0.65,0.8,0.3])
3 调节子图相对位置 ——— 可 一次性设置不同子图分布比例
3.1 自动调整
plot.tight_latout()
3.2 手动调整————间距变大,没有重合
plt.subplots_adjust(left=0.1, right=0.9,
bottom=0.1, top=0.9 ,
wspace=0.5, hspace=0.3)
#左边空出画布的0.1 右边0.9,下边0.1,上边0.9,wspace左右小图之间间隔-小图的宽度比例,hspace上下小图的间隔
fig((ax1, ax2),(ax3,ax4)) = plt. subp1ots(2,2, figsize = (5,5))
ax1.p1ot(data[ 'prec'],'k-')
ax2.plot(data[ 'prec'],'r-' )
2作图函数及其设置
############################################################################
#直方图
ax.hist(f.prec, bins = 25,density = True,
edgecolor ='k',facecolor = 'tab:cyan',
linewidth=1, linestyle='-') # bins 组数 ,density 概率密度
plt.title('Hist of the prec',font1)
ax.set_xlabel( 'Precipitation (mm)',font2)
ax.set_ylabel( 'Density',font2)
plt.grid(linestyle='--',alpha=0.1) #alpha 网格线透明度
############################################################################
#箱体图
ax.boxplot([f.temp,f.prec],labels = ['temp','prec'],
whis = (5,95),widths=0.3,
showmeans=True, showfliers=True,
boxprops = { 'color':'r', 'linewidth':1},
medianprops = { 'linestyle': '--', 'color':'r','linewidth':1},
whiskerprops = { 'linestyle':'--', 'color':'b', 'linewidth' :1},
capprops = { 'linestyle':'--','color':'r','linewidth':1},
flierprops = { 'marker': 'D' ,'markersize':1,
'markeredgecolor':'k','markerfacecolor':'none'})
plt.title('Boxplot of th prec and temp',font1)
#-------------显示
whis 置信水平
widths 箱体宽度比例(0-1)
showfiler 奇异值是否显示(ture显示)
showmeans 平均值是否显示
patch_artist 箱体是否填充
#-------------props属性
box 箱体属性
median 中间这条线的属性
whiske 胡须-箱体上下的虚线属性
cap 上下横线属性
###########################################################################
#散点图
ax.scatter(f.temp,f.prec,
marker = 'o',c=t_clr,s=14,
edgecolor = 'b', linewidths = 1) #s符号大小
ax.set(xlim=(26,34),ylim=(250, 340),
xticks = np.arange(26,35,2),
yticks = np.arange(250,341,15))
plt.title('Scatter of the prec and temp',font1)
ax.tick_params(labelsize=10,pad=3) #labelsize设置刻度线标签的字体大小 #pad设置刻度线与标签间的距离
ax.set_xlabel('Temperature ($^{ \circ}$C) ',font2)
ax.set_ylabel('Precipitation (mm) ',font2)