matplotlib:在极地图中填充两个曲线之间的圆形扇形

发布于 2025-02-13 03:28:00 字数 529 浏览 2 评论 0原文

因此,我有两条曲线theta1(r)theta2(r),其中r均匀地间隔了两个数字(1和330 in这种情况)。如何填充两条曲线之间的径向段?

我已经考虑过适应 this 似乎不合时宜。提供解决方案依赖于反向关系,r(theta),这是模棱两可的,因此在我的情况下是不适用的。

So I have two curves theta1(r) and theta2(r), where r is uniformly spaced between some two numbers (1 and 330 in this case). How can I fill the radial segment between the two curves?

I have considered adapting this solution, but it does not seem useful out of the box. Provided solution relies on an inverse relation, r(theta), which would be ambiguous and thus inapplicable in my case.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吖咩 2025-02-20 03:28:00

一个选项是使a 的圆形部门

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np


fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))

n = 330
r = np.arange(330)

# auto correlate random numbers (see comment below)
a = np.zeros(n) + np.add.accumulate(np.random.normal(0, np.pi / 180, size=n))
b = np.ones(n) * np.pi / 2 + np.add.accumulate(np.random.normal(0, np.pi / 180, size=n))

ax.plot(a, r)
ax.plot(b, r)

arc_theta = np.linspace(a[-1], b[-1], 101)
arc_r = np.ones_like(arc_theta) * 330

start = np.c_[a, r]
arc = np.c_[arc_theta, arc_r]
end = np.c_[b, r][::-1]

verts = np.concatenate([start, arc, end])

p = Polygon(verts, fc="purple", alpha=0.5)
ax.add_artist(p)

plt.show()

给出

One option is to make a Polygon of the circular sector

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np


fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))

n = 330
r = np.arange(330)

# auto correlate random numbers (see comment below)
a = np.zeros(n) + np.add.accumulate(np.random.normal(0, np.pi / 180, size=n))
b = np.ones(n) * np.pi / 2 + np.add.accumulate(np.random.normal(0, np.pi / 180, size=n))

ax.plot(a, r)
ax.plot(b, r)

arc_theta = np.linspace(a[-1], b[-1], 101)
arc_r = np.ones_like(arc_theta) * 330

start = np.c_[a, r]
arc = np.c_[arc_theta, arc_r]
end = np.c_[b, r][::-1]

verts = np.concatenate([start, arc, end])

p = Polygon(verts, fc="purple", alpha=0.5)
ax.add_artist(p)

plt.show()

gives

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文