用matplotlib fill_bet_bet_bet_bet_betthe填充两条极性曲线的常见内部

发布于 2025-02-07 02:56:10 字数 740 浏览 2 评论 0原文

我正在尝试在极坐标(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'.

Resulting plot

Perhaps I don't understand the 'where' argument of 'fill_between'. Any ideas?

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

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

发布评论

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

评论(1

标点 2025-02-14 02:56:10

您的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)适合图。

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, abs(r2))

plt.polar(phi, r1)
plt.polar(phi, r2)
plt.ylim(min(r1),max(r2))
plt.fill_between(phi, min(r1), r3, color='#D0D0FF')
plt.show()

希望这会有所帮助!

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 to min(r1) and the r-axis limits to min(r1) and max(r2) to fit the plot.

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, abs(r2))

plt.polar(phi, r1)
plt.polar(phi, r2)
plt.ylim(min(r1),max(r2))
plt.fill_between(phi, min(r1), r3, color='#D0D0FF')
plt.show()

enter image description here

Hope this helps !

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