首页 > 解决方案 > 带有浮点输入变量的python绘图图

问题描述

我想问一下 python 绘制 matplotlib.pyplot 图 例如,如果 mu 函数就像 y1 = ax b+c d y2 =a**2+bx+c*d 那么 x 在 0 到 10 的范围内如何绘制图形如果我的 a,b,c 需要自己的号码,例如

a = float(input('Enter a:'))
b = float(input('Enter b:'))
c = float(input('Enter c:'))

y1 和 y2 也需要在同一个图中绘图

标签: pythoninputgraph

解决方案


Matplotlib 适用于您的大多数绘图需求。它将列表作为输入,因此您需要准备数据。我使用了列表压缩,但您也可以使用 for 循环来获取您的值。之后,您可以进行绘图和显示。

import matplotlib.pyplot as plt

a = float(input('Enter a:'))
b = float(input('Enter b:'))
c = float(input('Enter c:'))
d = float(input('Enter d:'))

y1 = [a*b*x + c*d for x in range(0,11)]
y2 = [a**2+b*x+c*d for x in range(0,11)]

plt.plot(y1)
plt.plot(y2)
plt.show()

推荐阅读