subplot
- 基本用法
| plt.subplot(nrows, ncols, index) |
| |
| |
| |
| |
| plt.subplot(2,2,1) |
| x = np.arange(0,math.pi*2,0.05) |
| plt.plot(x,np.sin(x),'y-') |
| plt.subplot(2,2,4) |
| plt.plot(x,np.cos(x),'b.') |
- add_subplot(nrows,ncols,index)
| |
| fig = plt.figure() |
| ax1 = fig.add_subplot(1,1,1) |
| ax1.plot(x,sin(x)) |
| ax1.set_title('wave') |
| ax2 = fig.add_subplot(2,2,2) |
| ax2.plot(x,cos(x)) |
| ax2.set_title('wave2') |
- 使用add_axes也可以达到同一画布添加多个图形的效果
| |
| import matplotlib.pyplot as plt |
| import math |
| import numpy as np |
| x = np.arange(0,math.pi*2,0.05) |
| fig = plt.figure() |
| ax1 = fig.add_axes([0,0,1,1]) |
| ax1.plot(x,np.sin(x)) |
| ax2 = fig.add_axes([.5,0.5,.5,.5]) |
| ax2.plot(x,np.cos(x)) |
| plt.show() |
subplots()
它的使用方法和 subplot() 函数类似。其不同之处在于,subplots() 既创建了一个包含子图区域的画布,又创建了一个 figure 图形对象,而 subplot() 只是创建一个包含子图区域的画布。
| fig , ax = plt.subplots(nrows, ncols) |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| import math |
| fig,ax = plt.subplots(2,2) |
| ax[0,1].plot(x,np.sin(x)) |
| ax[1,0].plot(x,np.cos(x)) |
subplot2grid()
| |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| import math |
| a1 = plt.subplot2grid((3,3),(0,0),colspan=2) |
| a2 = plt.subplot2grid((3,3),(0,2),rowspan=3) |
| a3 = plt.subplot2grid((3,3),(1,0),colspan=2,rowspan=2) |
| x = np.arange(0,math.pi*2,0.05) |
| a1.plot(x,sin(x)) |
| a2.plot(x,cos(x)) |
| a3.plot(x,tan(x)) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人