python 绘制黄金分割率的指数函数的曲线
编写 test_gold_x.py 如下
# -*- coding: utf-8 -*-
""" 黄金分割率的指数函数 y=0.618^x 和 y=1.618^x 的曲线 """
import numpy as np
from matplotlib import pyplot as plt
# 用于正常显示中文标题,负号
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.arange(-3.0, 3.01, 0.01)
y = np.power(0.618, x)
y1 = np.power(1.618, x)
print(len(x))
print('0.618^x:', y[0], y[-1])
print('1.618^x:', y1[0],y1[-1])
# 可视化
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y, label='0.618^x') # 画曲线
axes.plot(x, y1, label='1.618^x')
#axes.axis('scaled') # 用缩尺制图
axes.axis('equal')
plt.title('指数函数 y=0.618^x 和 y=1.618^x 的曲线')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()
运行 python test_gold_x.py

1851

被折叠的 条评论
为什么被折叠?



