python matplotlib极坐标p

2024-04-26 03:26:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用下面的代码来创建一个窦的极图。

import numpy as np
import matplotlib.pyplot as plt


theta = np.arange(0, 2*np.pi, .01)[1:]
plt.polar(theta, sin(theta))
plt.show()

产生:

enter image description here

但我想把它画成对称的,像这样:

enter image description here

我怎样才能得到我想要的结果?


Tags: 代码importnumpymatplotlibasshownppi
2条回答

matplotlib极轴允许负半径。所以,如果你想要对称的图,你需要绘制sin的绝对值:

polar(theta, abs(sin(theta)))

enter image description here

另外,您需要绘制与sin(theta)相反的图:

plt.polar(theta, sin(theta))
plt.polar(theta, -sin(theta))

enter image description here

相关问题 更多 >