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

How to fill between 3 lines in a polar plot?

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

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()

您需要稍微修改您的代码以包含您要绘制的区域,然后使用 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()

将绘制: