Sarah
Sarah

Reputation: 75

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 ?

Upvotes: 4

Views: 4545

Answers (2)

Balaji Raman
Balaji Raman

Reputation: 21

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()

Upvotes: 2

brice
brice

Reputation: 25039

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()

Upvotes: 10

Related Questions