点击查看代码
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
plt.subplot(221)
plt.plot(x, x)
plt.subplot(222)
plt.plot(x, -x)
plt.subplot(223)
plt.plot(x, x ** 2)
plt.grid(color='r', linestyle='--', linewidth=1, alpha=0.3)
plt.subplot(224)
plt.plot(x, np.log(x))
plt.show()

点击查看代码
import numpy as np
import matplotlib.pyplot as plt
# subplots创建多个子图
x = np.arange(0, 100)
# 划分子图
fig, axes = plt.subplots(2, 2)
ax1 = axes[0, 0]
ax2 = axes[0, 1]
ax3 = axes[1, 0]
ax4 = axes[1, 1]
# 作图1
ax1.plot(x, x)
# 作图2
ax2.plot(x, x)
# 作图3
ax3.plot(x, x ** 2)
ax3.grid(color='r', linestyle='
# 作图4
ax4.plot(x, np.log(x))
plt.show()

点击查看代码
import numpy as np
import matplotlib.pyplot as plt
# add_subplot新增子图
x = np.arange(0, 100)
# 新建figure对象
fig = plt.figure()
# 新建子图1
ax1 = fig.add_subplot(2, 2, 1)
ax1.plot(x, x)
# 新建子图3
ax3 = fig.add_subplot(2, 2, 3)
ax3.plot(x, x ** 2)
ax3.grid(color='r', linestyle='
plt.show()

点击查看代码
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = [1, 2, 3, 4, 5, 6, 7]
y = [1, 3, 4, 2, 5, 8, 6]
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
ax1 = fig.add_axes([left, bottom, width, height])
ax1.plot(x, y, 'r')
ax1.set_title('area1')
left, bottom, width, height = 0.2, 0.6, 0.25, 0.25
ax2 = fig.add_axes([left, bottom, width, height])
ax2.plot(x, y, 'b')
ax2.set_title('area2')
plt.show()

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)