如何使用Python绘制一个带颜色的扇形?

4

我需要可视化传感器的视野。因此,我需要使用Python Matplotlib绘制一个扇形并填充该扇形的颜色(alpha <1)。有什么建议吗?

2个回答

10

使用楔形图元素

enter image description here

如下:

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

fig=plt.figure()
ax=fig.add_subplot(111) 

fov = Wedge((.2,.2), 0.6, 30, 60, color="r", alpha=0.5)

ax.add_artist(fov)

plt.show()

2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
fig1 = plt.figure()
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.add_patch(
    patches.Wedge(
        (0, 0),         # (x,y)
        200,            # radius
        60,             # theta1 (in degrees)
        120,            # theta2
        color="g", alpha=0.2
    )
)

plt.axis([-150, 150, 0, 250])

plt.show()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接