用matplotlib fill_bet_bet_bet_bet_betthe填充两条极性曲线的常见内部
我正在尝试在极坐标(r1 = sqrt(3)* sin(φ)和r2 = 1- cos(φ))中填充圆和心形的内部。 我在”中找到了一个简单的解决方案。 - 找到两个功能的最低功能,并填充0至最小值之间的区域。 代码:
import matplotlib.pyplot as plt
import numpy as np
import math
phi = np.arange(0, (2 * np.pi), 0.01)
r1 = math.sqrt(3) * np.sin(phi)
r2 = 1 - np.cos(phi)
r3 = np.minimum(r1, r2)
plt.polar(phi, r1)
plt.polar(phi, r2)
plt.fill_between(phi, 0, r3, color='#D0D0FF')
plt.show()
但是最终结果很奇怪。 φ从2π到0的底部是“倒置”。
也许我不了解'fill_betewneed'的'where'论点。有什么想法吗?
I'm trying to fill the common interior of circle and cardioid in polar coordinates (r1= sqrt(3)* sin(φ) and r2= 1 - cos(φ)).
I've found a simple solution in this question — find the minimum of two functions and fill an area between 0 and minimum.
Code:
import matplotlib.pyplot as plt
import numpy as np
import math
phi = np.arange(0, (2 * np.pi), 0.01)
r1 = math.sqrt(3) * np.sin(phi)
r2 = 1 - np.cos(phi)
r3 = np.minimum(r1, r2)
plt.polar(phi, r1)
plt.polar(phi, r2)
plt.fill_between(phi, 0, r3, color='#D0D0FF')
plt.show()
But the end result is strange. The bottom part, where φ goes from 2π to 0, is 'inverted'.
Perhaps I don't understand the 'where' argument of 'fill_between'. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的Polar Plot的径向轴的范围从大约-1.7到2。
因此,使用您的呼叫
plt.fill_between(Phi,0,R3,color ='#d0d0ff')
您缺少了当cradiod下降到0以下时,零件之间的一部分。此修改代码将起作用:我将0在
fill_between
中更改为min(r1)
和R轴限制到min(r1)
和max(r2)
适合图。希望这会有所帮助!
Your polar plot's radial axis has a range that goes from approximately -1.7 to 2.
So with your call
plt.fill_between(phi, 0, r3, color='#D0D0FF')
you're missing the part between -1.7 and 0 when the cradiod dips below 0.This modified code will work : I changed the 0 in
fill_between
tomin(r1)
and the r-axis limits tomin(r1)
andmax(r2)
to fit the plot.Hope this helps !