gpt4 book ai didi

python - 在 Python 中使用 Matplotlib 绘制抛物线

转载 作者:太空狗 更新时间:2023-10-29 22:11:02 25 4
gpt4 key购买 nike

我试图在 matplotlib 中绘制一个简单的抛物线,但我对如何在抛物线上绘制点感到困惑。到目前为止,这就是我所拥有的:

import matplotlib.pyplot as plt
a=[]
b=[]
y=0
x=-50
while x in range(-50,50,1):
y=x^2+2*x+2
a=[x]
b=[y]
fig= plt.figure()
axes=fig.add_subplot(111)
axes.plot(a,b)
plt.show()
x= x+1

最佳答案

应该这样做:

import matplotlib.pyplot as plt
import numpy as np

# create 1000 equally spaced points between -10 and 10
x = np.linspace(-10, 10, 1000)

# calculate the y value for each element of the x vector
y = x**2 + 2*x + 2

fig, ax = plt.subplots()
ax.plot(x, y)

mpl-plot

关于python - 在 Python 中使用 Matplotlib 绘制抛物线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30553585/

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