1. Home
  2. Docs
  3. Python-DataScience
  4. Visualization with Matplotlib
  5. Subplot & Subplots

Subplot & Subplots

subplots functions

subplots

可以一次返回canvas 和 多个 ax, 但是此处返回的ax为array格式,需要指定ax进行绘图。

# subplots可以定义连同 canvas画布一次定义多个 
fig, ax = plt.subplots(nrows=3, ncols=4, figsize=(32,18))

   y = df.iloc(axis=1)[i]
   ax[1][i].ylabel(y.name)
   ax[1][i].plot(y)

subplot

# plt.subplot一次只能定义一个子图
# 且每次都要以实例方式读取
for i in range(12):
    
    y = df.iloc(axis=1)[i]
    ax = plt.subplot(3, 4, i+1)
    ax.plot(y)
    ax.set_ylabel(y.name)
    
plt.show()

subplot2grid

ax1= plt.subplot2grid(shape=(2,2), loc=(0,0), colspan=2)
ax2= plt.subplot2grid( (2,2), (1,1) )
ax3= plt.subplot2grid( (2, 2), (1,0) )
Was this article helpful to you? Yes No

How can we help?