2011-05-13 16 views
5
>>> import matplotlib 
>>> matplotlib.__version__ 
'0.99.1.1' 

Aşağıdaki kod çalışan iterable değildir:açıklama matplotlib xycoords => = ('Veri', 'kısmını eksenleri') TypeError: 'NoneType' nesne

import matplotlib.pyplot as plt 
plt.figure() 
ax=plt.axes([.1, .1, .8, .8]) 
ax.annotate('++++', xy=(.5,.2), xycoords='data') 
ax.annotate('aaaa', xy=(.5,.4), xycoords='axes fraction') 
#ax.annotate('bbbb', xy=(.5,.6), xycoords=('data', 'axes fraction')) 
plt.show() 

ancak çok yorum Çıkış balta.

From: http://matplotlib.sourceforge.net/users/annotations_guide.html 

4. A tuple of two coordinate specification. 
    The first item is for x-coordinate and 
    the second is for y-coordinate. 
    For example, 

     annotate("Test", xy=(0.5, 1), xycoords=("data", "axes fraction")) 

    0.5 is in data coordinate, and 1 is in normalized axes coordinate. 
: o anki docs göre güya doğru kodudur

TypeError: 'NoneType' object is not iterable 

: Annotatesekmesindeki hata veriyor 210

Neler olduğu hakkında herhangi bir fikir var mı?

DÜZENLEME: ilk gönderiden beri, bir geçici çözüm arıyorum ve başka bir sorun keşfettim. Xycoords = 'data' olduğunda, clip_on = False ile bile, eksenlerin dışına düşerse annotataion hala kırpılır.

import matplotlib.pyplot as plt 
plt.figure() 
ax=plt.axes([.1, .1, .8, .8]) 
ax.annotate('cccc', xy=(.3, .5), xycoords='data', clip_on=False) 
ax.annotate('dddd', xy=(.3,-.1), xycoords='data', clip_on=False) 
ax.annotate('eeee', xy=(.6,-.1), xycoords='axes fraction', clip_on=False) 
plt.show() 
+0

Matplotlib'in hangi sürümünü kullanıyorsunuz? Her iki örneğiniz benim için mükemmel çalışıyor ... –

+0

teşekkürler Joe, matplotlib .__ version__ '0.99.1.1' .... hangi sürümü kullanıyorsunuz? –

+0

@mike - '1.0.1' Bence" xcoords "kwarg parçasının" iki koordinat belirtiminin tuple "kısmı matplotlib 1.0'a eklenmiştir. Http://matplotlib.sourceforge.net/_static/CHANGELOG adresindeki 2010-02-25'deki eke bakın. İkinci problem, bir noktada düzeltilen bir hatadır. (Aslında, sadece 0.99.1'de var olan bir hata olduğunu iddia ediyorum. Uzun süre fark edilmeden gitmeyi düşünmüyorum.) –

cevap

4

matplotlib 1.0 eklendi farklı x ve annotate için y dönüşümleri belirtmek için bir başlığın kullanılması: İşte bu gösteriyor koddur. Here's the relevant commit, ilgilenen varsa. Kullanmak için en son sürüme yükseltmeniz gerekir.

İkinci sorun için, bu aslında belgelenen davranıştır. (.. clip_on Ek Açıklama sanatçılar görünüşe göre, aynı şekilde davranmazlar genel matplotlib metin sanatçı kwarg), dan

: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.annotate

The annotation_clip attribute contols the visibility of the annotation when it goes outside the axes area. If True, the annotation will only be drawn when the xy is inside the axes. If False, the annotation will always be drawn regardless of its position. The default is None, which behave as True only if xycoords is”data”.

yerine, annotation_clip kwarg kullanmanız gerekir:

import matplotlib.pyplot as plt 
plt.figure() 
ax=plt.axes([.1, .1, .8, .8]) 
ax.annotate('cccc', xy=(.3, .5), xycoords='data', annotation_clip=False) 
ax.annotate('dddd', xy=(.3,-.1), xycoords='data', annotation_clip=False) 
ax.annotate('eeee', xy=(.6,-.1), xycoords='axes fraction', annotation_clip=False) 
plt.show() 

daha tartışma için this thread on the matplotlib-users list görün (ve workaroun kullanmanız gerekebilir böylece de, annotation_clip kwarg 0.99.1 üzerine kırılmış olabilir unutmayın d var.)

İlgili konular