matplotlib的基本用法(十四)——figure图的嵌套

来源:互联网 发布:时代网络大厦 编辑:程序博客网 时间:2024/06/06 11:02

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

本文主要使用matplotlib进行图嵌套的绘制。

  • Demo
import matplotlib.pyplot as plt# 定义figurefig = plt.figure()# 定义数据x = [1, 2, 3, 4, 5, 6, 7]y = [1, 3, 4, 2, 5, 8, 6]# figure的百分比, 从figure 10%的位置开始绘制, 宽高是figure的80%left, bottom, width, height = 0.1, 0.1, 0.8, 0.8# 获得绘制的句柄ax1 = fig.add_axes([left, bottom, width, height])# 绘制点(x,y)ax1.plot(x, y, 'r')ax1.set_xlabel('x')ax1.set_ylabel('y')ax1.set_title('test')# 嵌套方法一# figure的百分比, 从figure 10%的位置开始绘制, 宽高是figure的80%left, bottom, width, height = 0.2, 0.6, 0.25, 0.25# 获得绘制的句柄ax2 = fig.add_axes([left, bottom, width, height])# 绘制点(x,y)ax2.plot(x, y, 'r')ax2.set_xlabel('x')ax2.set_ylabel('y')ax2.set_title('part1')# 嵌套方法二plt.axes([bottom, left, width, height])plt.plot(x, y, 'r')plt.xlabel('x')plt.ylabel('y')plt.title('part2')plt.show()
  • 结果

图像

0 0
原创粉丝点击