for i inrange(1,7):
plt.subplot(2,3,i)#plt.subplot(2,3,1)也可写成plt.subplot(231).#另一种调用方式是用plt.subplot(ax),即传递一个Axes对象。这样可以直接把图的内容画出来
plt.text(0.5,0.5,str((2,3,i)),fontsize=18,ha='center')
plt.subplots_adjust(wspace=1,hspace=0.2)#注意这里的range(1,7)是因为plt.subplot的子图索引是从一开始(与MATLAB同),面向对象同。#plt.subplots索引是从0开始,#这个查docstring,很简单但不好记#注意wspace与hspace就好。宽度间隔和高度间隔。#是平均子图宽度与高度的百分比
fig=plt.figure()
fig.subplots_adjust(wspace=0.3,hspace=0.2)for i inrange(1,7):
ax=fig.add_subplot(2,3,i)#注意是subplot不是复数#返回一个ax对象。
ax.text(0.5,0.5,str((2,3,i)),fontsize=18,ha='center')
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x000002568D9C43D0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000002568D9EEC40>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000002568DA35280>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x000002568DA5D910>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000002568DA87FD0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x000002568DACA340>]],
dtype=object)
for i inrange(2):for j inrange(3):
ax[i,j].text(0.5,0.5,str((2,3,i)),fontsize=18,ha='center')
fig
#返回值(数组)的用法。
子图import matplotlib.pyplot as pltimport numpy as npimport matplotlib as mplplt.style.use('seaborn-white')#注意是-而不是_%matplotlib inlineaxi=plt.axes()axii=plt.axes([0.65,0.65,0.2,0.2])#图形坐标系统的四个值[...