[英]Plot a spiral where r=theta^2 for 0<= theta <= 10*pi …in python
so my question is how to make a polar plot r = f(theta)
for a function f
by calculating r
for a range of values of theta and then converting r
and theta to Cartesian coordinates using equations x = r cos(theta)
, y = r sin(theta)
. 所以我的问题是如何使一个极坐标图
r = f(theta)
为一个函数f
通过计算r
为一系列theta的值,然后转换r
使用公式和θ为笛卡尔坐标x = r cos(theta)
y = r sin(theta)
。
BUT I need to plot the spiral r = (theta)^2
for 0 <= theta <= 10*pi
this is what I have so far....not getting a spiral here. 但是我需要绘制螺旋
r = (theta)^2
为0 <= theta <= 10*pi
这是我到目前为止所得到的......没有在这里获得螺旋。
#! /usr/bin/env python
import matplotlib.pyplot as plt
from math import cos, sin, pi
from numpy import linspace
for theta in linspace(0,10*pi):
r = ((theta)**2)
x = r*cos(theta)
y = r*sin(theta)
plt.plot(x,y)
plt.savefig("spiral.png")
plt.show()
You need to create a list of values, not just a single point. 您需要创建值列表,而不仅仅是单个点。 In your case, you keep calculating
x
and y
, but never save them anywhere. 在你的情况下,你继续计算
x
和y
,但从不将它们保存在任何地方。 So all you are plotting is the pair (x,y)
after the last iteration. 所以你要绘制的是最后一次迭代后的对
(x,y)
。
x = []
y = []
for theta in linspace(0,10*pi):
r = ((theta)**2)
x.append(r*cos(theta))
y.append(r*sin(theta))
plt.plot(x,y)
plt.show()
Output 产量
import numpy as np
import matplotlib.pyplot as plt
theta = np.radians(np.linspace(0,360*5,1000))
r = theta**2
x_2 = r*np.cos(theta)
y_2 = r*np.sin(theta)
plt.figure(figsize=[10,10])
plt.plot(x_2,y_2)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.