Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to draw a colored sector using python?

I need to visualize the field of view of a sensor. So, I need to draw a sector using python matplotlib and fill this sector with a color (alpha<1). Any suggestions please ?

like image 987
Sarah Avatar asked Dec 21 '22 03:12

Sarah


2 Answers

Use a Wedge Artist:

enter image description here

As follows:

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()
like image 124
brice Avatar answered Dec 29 '22 17:12

brice


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()
like image 39
Balaji Raman Avatar answered Dec 29 '22 18:12

Balaji Raman