【问题标题】:How to fill between 3 lines in a polar plot?如何在极坐标图中填充 3 行之间?
【发布时间】:2020-06-18 08:08:03
【问题描述】:

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

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

【问题讨论】:

  • 请提供完整的可执行程序。
  • 抱歉我忘了复制粘贴导入

标签: python matplotlib polar-coordinates


【解决方案1】:

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

将绘制:

【讨论】:

  • 谢谢!这正是我要找的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-02-08
  • 1970-01-01
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-06
相关资源
最近更新 更多