python - 从数学函数创建图形

标签 python function math matplotlib graph

我在学习用 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/

相关文章:

javascript - 使用函数参数进行对象解构

function - Ada 函数头中的可选注释部分

html - Angular ng 模型表达式

java - libGDX - 如何将多边形绘制为一条线(斜接连接类型)?

python - 如何根据列表项拆分列表并创建相关字符串

python - 如何在 Python 上使用正则表达式删除括号?

python - 字符串格式的电子邮件的有效负载,python

c - 将多维数组传递给 C 中的函数

math - 在频域中乘以图像

python - OSError : [Errno 22] Invalid argument on file path while modifying a file