2016-03-27 30 views
0

Ya da daha ayrıntılı olarak, sağ üst köşedeki [659] '659 derece'ye nasıl değiştirebilirim?Matplotlib'de bir imshow çiziminin veri görüntüleme formatını nasıl değiştirebilirim?

enter image description here

aşağıdaki cevapta belirtilen tüm konuları kontrol ettikten: matplotlib values under cursor. Ancak, hepsi, imlecin x, y konumuna hitap ediyor gibi görünüyor. Veri değerini değiştirmekle ilgileniyorum. API'de bir yanıt veya ilgili belgeleri bulamadım.

Hem format_coord(x, y) hem de format_cursor_data(data)'u denedim, ancak bunların ikisi de çalışmıyor gibi görünüyor.

sayesinde Sarith

PS: Kodum birden modüllerde ve gui uygulamanın bir parçası. İlgili bölümleri, bunu yanıtlarken herhangi bir yardımın olması durumunda paylaşabilirim.

Bu görüntüler, x, y ve z, değeri derece bir ile z sonra: matplotlib bir example değiştirerek

+0

garip şey genellikle zaten bunun için bir işlevi olmalıdır böylece 'bile, x ve y koordinatları gösterir .. – JeD

cevap

0

Bu kod var.

Kolayca değiştirebilmeniz veya ilgili işlevleri kopyalayabilmeniz gerekir.

Zaten format_coord'u denediniz dediniz, belki de işlevini ayarlamayı unuttun mu? (ikinci son satır)

""" 
Show how to modify the coordinate formatter to report the image "z" 
value of the nearest pixel given x and y 
""" 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.cm as cm 

X = 10*np.random.rand(5, 3) 

fig, ax = plt.subplots() 
ax.imshow(X, cmap=cm.jet, interpolation='nearest') 

numrows, numcols = X.shape 


def format_coord(x, y): 
    col = int(x + 0.5) 
    row = int(y + 0.5) 
    if col >= 0 and col < numcols and row >= 0 and row < numrows: 

     #get z from your data, given x and y 
     z = X[row, col] 

     #this only leaves two decimal points for readability 
     [x,y,z]=map("{0:.2f}".format,[x,y,z]) 

     #change return string of x,y and z to whatever you want 
     return 'x='+str(x)+', y='+str(y)+', z='+str(z)+" degrees" 
    else: 
     return 'x=%1.4f, y=%1.4f' % (x, y) 

#Set the function as the one used for display 
ax.format_coord = format_coord 
plt.show() 
+0

Merhaba, yanıtlama için teşekkürler gelmez olmasıdır. Ama bu bunu yapmıyor. Sadece "x = 0.01, y = 0.02 z = 0.40 derece [3.4]" gibi bir şey görüntüler (aslında kafa karıştırıcıdır). Demek istediğim, "x = 0.01, y = 0.02, 3.4 derece" gibi bir şeydi. Belki de çok fazla soruyorum:/ –

+0

[3.4] 'u nereden alıyorsunuz? Otomatik olarak oluşturuluyor mu? Dönüşü değiştirmeyi deneyin x = '+ str (x) +', y = '+ str (y) +', z = '+ str (z) + "derece" ile "geri" x =' + str (x) + ', y =' + str (y) + ', z =' + "Deg:" '. Bu, en azından "x = 0,01, y = 0,02, Deg: [3,4]" ' – JeD

+0

göstermelidir. Sadece kendi başına görünür. Matplotlib 1.5.1 kullanıyorum. İşte kodunuzdan ekran görüntüsü: https://www.dropbox.com/s/aim7h7o866ht4oq/Untitled.jpg?dl=0 –

İlgili konular