2016-09-30 102 views
2

我試圖通過修改其center屬性來改變matplotlib.patches.Wedge的位置,但它似乎沒有任何作用。楔形補丁未更新

例如:

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

產生如下:

sad

這顯然是不正確。

類似的方法功能罰款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

而且matplotlib.patches.Rectangle(從centerxy到的變化)

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

我認爲這可能是Wedge利用xy而不是center,但Wedge對象沒有xy屬性。我在這裏錯過了什麼?

回答

1

你可能不得不updateWedge的屬性:

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

正如你看到的,該方法接受一個字典,它指定的屬性進行更新。

result