python画多个图

import matplotlib.pyplot as plt
import numpy as np

# 生成一些示例数据
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)

# 创建一个2x2的子图布局
fig, axs = plt.subplots(2, 2, figsize=(10, 8))

# 在第一个子图上绘制sin(x)
axs[0, 0].plot(x, y1, label='sin(x)')
axs[0, 0].set_title('Sine Function')
axs[0, 0].legend()

# 在第二个子图上绘制cos(x)
axs[0, 1].plot(x, y2, label='cos(x)', color='green')
axs[0, 1].set_title('Cosine Function')
axs[0, 1].legend()

# 在第三个子图上绘制tan(x)(注意:tan(x)在某些点会趋于无穷大)
axs[1, 0].plot(x, y3, label='tan(x)', color='red')
axs[1, 0].set_title('Tangent Function')
axs[1, 0].legend()

# 在第四个子图上绘制sin(x)和cos(x)的叠加
axs[1, 1].plot(x, y1, label='sin(x)')
axs[1, 1].plot(x, y2, label='cos(x)', color='green')
axs[1, 1].set_title('Sine and Cosine Functions')
axs[1, 1].legend()

# 调整布局以防止子图重叠
plt.tight_layout()

# 显示图形
plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值