Python+Matplotlib可视化y = e^(1/x)函数

可视化y = e^(1/x)函数:

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

fig, ax = plt.subplots(figsize=(12, 8))

def e_to_1_over_x(x):
    return np.where(x != 0, np.exp(1/x), np.nan)

# 线性刻度图
x_linear = np.linspace(-10, 10, 10000)
y_linear = e_to_1_over_x(x_linear)

ax.plot(x_linear, y_linear, 'b')
ax.set_title('y = e^(1/x)')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.grid(True, alpha=0.3)
ax.set_ylim(-1, 5)
ax.set_xlim(-10, 10)

# 添加红色的 X=0 和 Y=0 轴
ax.axhline(y=0, color='r', linewidth=1.5)
ax.axvline(x=0, color='r', linewidth=1.5)

# 添加水平渐近线
ax.axhline(y=1, color='g', linestyle='--', alpha=0.7)
ax.text(5, 1.1, 'y = 1 (水平渐近线)', color='g')

# 添加注释
ax.annotate('x → 0+, y → +∞', xy=(0.5, 4.5), xytext=(2, 4),
            arrowprops=dict(facecolor='black', shrink=0.05))
ax.annotate('x → 0-, y → 0', xy=(-0.5, 0.1), xytext=(-3, 0.5),
            arrowprops=dict(facecolor='black', shrink=0.05))
ax.annotate('x → +∞, y → 1', xy=(8, 1.1), xytext=(6, 2),
            arrowprops=dict(facecolor='black', shrink=0.05))
ax.annotate('x → -∞, y → 1', xy=(-8, 1.1), xytext=(-6, 2),
            arrowprops=dict(facecolor='black', shrink=0.05))

plt.tight_layout()
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

脑子不好真君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值