REF
https://www.zhihu.com/question/51745620
import matplotlib.pyplot as plt fig = plt.figure(1) ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) print(type(ax1)) # <class 'matplotlib.axes._subplots.AxesSubplot'> plt.show() import matplotlib.pyplot as plt fig = plt.figure(2) ax3 = fig.add_axes([0.1, 0.1, 0.8, 0.8])
ax4 = fig.add_axes([0.72,0.72,0.16,0.16])
print(type(ax3)) # <class 'matplotlib.axes._axes.Axes'> plt.show()
可以把figure想象成windows的桌面,你可以有好幾個桌面。然后axes就是桌面上的圖標,subplot也是圖標,他們的區別在:axes是自由擺放的圖標,甚至可以相互重疊,而subplot是“自動對齊到網格”。但他們本質上都是圖標,也就是說subplot內部其實也是調用的axes,只不過規范了各個axes的排列罷了。
Most of you are probably familiar with the Subplot, which is just a special case of an Axes that lives on a regular rows by columns grid of Subplot instances. If you want to create an Axes at an arbitrary location, simply use the add_axes() method which takes a list of [left, bottom, width, height] values in 0-1 relative figure coordinates:
Matlab里面的概念:
https://ww2.mathworks.cn/help/matlab/ref/figure.html?s_tid=doc_ta
figure
使用默認屬性值創建一個新的圖窗窗口。生成的圖窗為當前圖窗。
https://ww2.mathworks.cn/help/matlab/ref/plot.html?s_tid=doc_ta
plot(
創建 X
,Y
)Y
中數據對 X
中對應值的二維線圖。
https://ww2.mathworks.cn/help/matlab/ref/subplot.html?s_tid=doc_ta
subplot(
將當前圖窗划分為 m
,n
,p
)m
×n
網格,並在 p
指定的位置創建坐標區。MATLAB® 按行號對子圖位置進行編號。第一個子圖是第一行的第一列,第二個子圖是第一行的第二列,依此類推。如果指定的位置已存在坐標區,則此命令會將該坐標區設為當前坐標區。
https://ww2.mathworks.cn/help/matlab/ref/axis.html?s_tid=doc_ta
axis(
指定當前坐標區的范圍。以包含 4 個、6 個或 8 個元素的向量形式指定范圍。limits
)
https://ww2.mathworks.cn/help/matlab/ref/axes.html?s_tid=doc_ta
axes
在當前圖窗中創建默認的笛卡爾坐標區,並將其設置為當前坐標區。通常情況下,您不需要在繪圖之前創建坐標區,因為如果不存在坐標區,圖形函數會在繪圖時自動創建坐標區。