[英]Fill Between Two Polar Curves with matplotlib fill_between
I have a feeling I'm going to be smacking my forehead on this one, but I'm trying to fill the common interior of two polar functions r = 4 sin(2θ)
and r = 2
. 我有一种感觉,我会在这一个上砸我的额头,但我试图填充两个极性函数的共同内部 r = 4 sin(2θ)
和r = 2
。 It seems I'm getting the opposite of what I want. 看来我正好与我想要的相反。 Any ideas? 有任何想法吗?
import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0, 2, 1./180)*np.pi
r = abs(4*np.sin(2*theta))
r2 = 2 + 0*theta
plt.polar(theta, r, lw=3)
plt.polar(theta, r2, lw=3)
plt.fill_between(theta, r, r2, alpha=0.2)
plt.show()
Perhaps compute the mininum of r and r2, and then fill between 0 and that minimum: 也许计算r和r2的最小值,然后在0和最小值之间填充:
import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0, 2, 1./180)*np.pi
r = abs(4*np.sin(2*theta))
r2 = 2 + 0*theta
r3 = np.minimum(r, r2)
plt.polar(theta, r, lw=3)
plt.polar(theta, r2, lw=3)
plt.fill_between(theta, 0, r3, alpha=0.2)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.