matplotlib-图中图 发表于 2019-06-11 | 分类于 python 详情请看莫烦老师教程莫烦python 代码123456789101112131415161718192021222324252627282930import matplotlib.pyplot as pltfig = plt.figure()x = [1, 2, 3, 4, 5, 6, 7]y = [1, 3, 4, 2, 5, 8, 6]# below are all percentageleft, bottom, width, height = 0.1, 0.1, 0.8, 0.8ax1 = fig.add_axes([left, bottom, width, height]) # main axesax1.plot(x, y, 'r')ax1.set_xlabel('x')ax1.set_ylabel('y')ax1.set_title('title')ax2 = fig.add_axes([0.2, 0.6, 0.25, 0.25]) # inside axesax2.plot(y, x, 'b')ax2.set_xlabel('x')ax2.set_ylabel('y')ax2.set_title('title inside 1')# different method to add axes####################################plt.axes([0.6, 0.2, 0.25, 0.25])plt.plot(y[::-1], x, 'g')plt.xlabel('x')plt.ylabel('y')plt.title('title inside 2')plt.show() 结果