[英]matplotlib: fill circular sector between two curves in a polar plot
所以我有两条曲线theta1(r)
和theta2(r)
,其中r
在一些两个数字(在这种情况下为 1 和 330)之间均匀分布。 如何填充两条曲线之间的径向段?
我考虑过调整这个解决方案,但它似乎没有开箱即用。 提供的解决方案依赖于逆关系r(theta)
,这将是模棱两可的,因此不适用于我的情况。
一种选择是制作圆形扇区的Polygon
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()
给
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.