python - 带有浮点输入变量的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 也需要在同一个图中绘图
解决方案
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()
推荐阅读
- javascript - JavaScript 尾递归超过最大调用堆栈
- ios - Swift - 每个视图中的响应视图?
- python - kivy 图像对撞机尺寸太大
- python - 如何有效地获取 DataFrame 的前 x%?
- python - python中的堆顺序
- gcc - gcc/ld 组合使用同一链接子库的不同版本的库
- caching - 大数据集的 Apollo InMemoryCache 性能策略(React)
- pivot - Excel - 数据透视表不计算平均丢失天数
- javascript - 如何使引导导航下拉项处于活动状态?
- python - pycharm中的远程调试,调试一个子进程