《高等数学》同济大学出版:指数函数 ,指数: exponential
e = 2.718281828459... 为自然常数
编写 test_exp_x.py 如下
# -*- coding: utf-8 -*-
""" 绘制指数函数 y=e^x 和 y=(1/e)^x 的曲线 """
import numpy as np
from matplotlib import pyplot as plt
# 用于正常显示中文标题,负号
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
e = np.e
x = np.arange(-2.0, 2.01, 0.01)
y = np.power(e, x)
y1 = np.power((1/e), x)
print(len(x), e)
print('e^x:', y[0], y[-1])
print('(1/e)^x:', y1[0], y1[-1])
# 可视化
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y, label='e^x') # 画曲线
axes.plot(x,y1, label='(1/e)^x')
#axes.axis('scaled') # 用缩尺制图
axes.axis('equal')