#! /usr/bin/env python # -*- coding: utf-8 -*- import matplotlib.pyplot as plt fig = plt.figure('subplot demo') # 图像标题为'subplot demo',否则默认为'Figure 1' # 接下来是在一个3行*2列的网格里添加子图 # row = 3, col = 2,该网格可以摆放六张子图index total为6 # fig.add_subplot(221) # row = 3, col = 2, index = 1 # equivalent but more general【与上面一行等价,但是这种更普遍】 ax1 = fig.add_subplot(3, 2, 1) # row = 3, col = 2, index = 1 # add a subplot with no frame ax2 = fig.add_subplot(322, frameon=False) # row = 3, col = 2, index = 2 # add a polar subplot fig.add_subplot(323, projection='polar') # row = 3, col = 2, index = 3 # add a red subplot that share the x-axis with ax1 fig.add_subplot(324, sharex=ax1, facecolor='red') # row = 3, col = 2, index = 4 # add a polar subplot fig.add_subplot(325, projection='lambert') # row = 3, col = 2, index = 5 # add a red subplot, mollweide 即是椭圆ellipse fig.add_subplot(326, projection='mollweide') # row = 3, col = 2, index = 6 # delete ax2 from the figure 删除子图 fig.delaxes(ax2) # # # add ax2 to the figure again 再次添加子图 fig.add_subplot(ax2) plt.show() # 显示图像