如何在python(matplotlib)中绘制2D圆锥体?

时间:2019-05-14 22:52:11

标签: python matplotlib

我是python的新手,正在制作一个房间的地图。我已经绘制了房间,障碍物等。还有一些点(它们是传感器)。现在,我要制作一个二维圆锥体,以显示传感器看到的区域。我将为圆锥体设置一个角度和半径。 我已经尝试搜索,但是在前面的问题中,大多数讨论了3-D圆锥。 How the cone should look

任何指导表示赞赏

2 个答案:

答案 0 :(得分:2)

您将使用matplotlib.patches.Wedge之类的this example。我已简化为更相关的另一个示例是:

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
import numpy as np

fig, ax = plt.subplots()

patches = []

wedge = mpatches.Wedge((.5, .5), 0.5, 30, 270, ec="none")
patches.append(wedge)

colors = np.linspace(0, 1, len(patches))
collection = PatchCollection(patches, cmap=plt.cm.hsv, alpha=0.3)
collection.set_array(np.array(colors))
ax.add_collection(collection)

plt.show()

哪个会产生类似的内容:

Wedge plot

显然,您需要将theta1theta2的{​​{1}}和30进行调整,以适应您要表示的任何角度,并将原点移动到任何位置传感器位于。另外,您可能希望为它们全部上色,而不是彩虹色,但我会让您弄清楚XD的细节

答案 1 :(得分:1)

最终使用以下内容:

import matplotlib.pyplot as plt
from matplotlib.patches import Wedge

fig, ax = plt.subplots()
patches=[]
ax.axis('equal')
we = Wedge((2756.6747,5339751.8148),10,30,180,edgecolor='b',facecolor='none')
patches.append(we)

ax.add_artist(we)
ax.set(xlim=[2740, 2800], ylim=[5339740, 5339780])

plt.show()

感谢@reedinationer给定的方向