我需要根据 r 在不同的 theta 值处等于什么来生成一个表。
我可以很容易地用 matplotlib 绘制和显示方程,并希望有一种简单的方法:
给 numpy theta 变量、我的曲线方程和 viola,返回 r 值
我试图查看 numpy 的文档,但很难找到我需要的东西。
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
mpl.style.use('default')
# Number of Points Ploted
# Change this numer to affect accuracy of the graph
n = 3000
theta = np.linspace(0, 2.0*np.pi, n)
def show_grid():
plt.grid(True)
plt.legend()
plt.show()
# Setting the range of theta to [0, 2π] for this specific equation
theta4 = np.linspace(0, 2*np.pi, n)
# Writing the equation
curve4 = 5*np.cos(64*theta)
ax1 = plt.subplot(111, polar=True)
ax1.plot(theta4, curve4, color='xkcd:cyan', label='CURVE 4: r = 5cos(64θ), [0, 2π)')
ax1.set_ylim(0,5)
ax1.set_yticks(np.linspace(0,5,6))
show_grid()
上面的代码很好地生成了一个图表,但是:
我可以使用相同的变量在 theta 处返回 r 吗?
HUWWW
相关分类