gpt4 book ai didi

python - 从数学函数创建图形

转载 作者:太空宇宙 更新时间:2023-11-04 03:25:15 28 4
gpt4 key购买 nike

我在学习用 Python 绘制函数时遇到了问题。例如,我想用这两个函数创建一个图表:

y=10x
y=5x+20

我找到的唯一方法是使用下面的代码

import matplotlib.pyplot as plt
plt.plot([points go here], [points go here])
plt.plot([points go here], [points go here])
plt.ylabel('some numbers')
plt.show()

并手动输入数据点,但我遇到了一些更棘手的问题,所以这真的很困难。

有没有办法只输入我需要绘图的函数并让 python 为我创建图表?

最佳答案

这很粗糙,但它会起作用:

import matplotlib.pyplot as plt
import random

x = [1, 2, 4,6, 7, 100, 200, 100, 34]
tenxArray = []
fiveXPlusTwenty = []

for i in range(0, len(x)):
tenxArray.append(10*x[i])
fiveXPlusTwenty.append(5*x[i] + 20)

plt.plot(x, tenxArray)
plt.plot(x, fiveXPlusTwenty)

plt.show()

关于python - 从数学函数创建图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33324083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com