如何在极坐标图中的3条线之间填充?

时间:2020-06-18 08:08:03

标签: python matplotlib polar-coordinates

我在极坐标图中绘制了一个圆和两条直线,我想在它们之间填充(四分之一圆)。但是我不知道如何。

enter image description here

import numpy as np
from matplotlib import pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, polar = True)

theta1 = np.linspace(0, 2*np.pi, 100)
r1 = theta*0 + 1
ax.plot(theta1, r1, color='b')

theta2 = np.array([np.pi/2]*100)
r2 = np.linspace(0, 1, 100)
ax.plot(theta2, r2, color='b')

theta3 = np.array([0]*100)
r3 = np.linspace(0, 1, 100)
ax.plot(theta3, r3, color='b')
plt.show()

1 个答案:

答案 0 :(得分:1)

您需要稍微修改代码以包含要绘制的区域,n使用fill_between方法。在第一象限的特定情况下,我们必须在0-90度和0-1半径之间填充。代码:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

theta1 = np.linspace(0, 2 * np.pi, 100)
r1 = theta1 * 0 + 1
ax.plot(theta1, r1, color='b')

theta2 = np.array([np.pi / 2] * 100)
r2 = np.linspace(0, 1, 100)
ax.plot(theta2, r2, color='b')

theta3 = np.array([0] * 100)
r3 = np.linspace(0, 1, 100)
ax.plot(theta3, r3, color='b')

theta4 = np.linspace(0, np.pi / 2, 100)
ax.fill_between(theta4, 0, 1)

plt.show()

情节: enter image description here

相关问题