excaza excaza - 2 months ago 12
Python Question

Wedge Patch Position Not Updating

I am attempting to shift the position of a

matplotlib.patches.Wedge
by modifying its
center
property, but it does not seem to have any effect.

For example:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

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

tmp = patches.Wedge([2, 2], 3, 0, 180)
ax.add_artist(tmp)
tmp.center = [4, 4] # Try to move!

ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
print(tmp.center)
plt.show()


Produces the following:

sad

Which is clearly incorrect.

A similar approach functions fine for
matplotlib.patches.Ellipse
:

import matplotlib.pyplot as plt
import matplotlib.patches as patches

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

tmp = patches.Ellipse([2, 2], 2, 2)
ax.add_artist(tmp)
tmp.center = [4, 4] # Try to move!

ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
print(tmp.center)
plt.show()


ellip

And
matplotlib.patches.Rectangle
(with the change from
center
to
xy
)

import matplotlib.pyplot as plt
import matplotlib.patches as patches

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

tmp = patches.Rectangle([2, 2], 3, 2)
ax.add_artist(tmp)
tmp.xy = [4, 4] # Try to move!

ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
print(tmp.xy)
plt.show()


rect

I thought it might be
Wedge
utilizing
xy
rather than
center
, but the
Wedge
object does not have an
xy
attribute. What am I missing here?

Answer

You probably have to update the properties of your Wedge:

tmp.update({'center': [4,4]})

As you see, the method accepts a dict that specifies the properties to update.

result

Comments