2016-02-08 108 views
0

當您使用imshow繪製窗口右下角的圖像時,會出現光標座標。然而,當我嘗試設置蜱和蜱軸的標籤窗口停止顯示座標和僅顯示「X = Y =」Matplotlib imshow:指定刻度時光標座標失敗

最少例如:

import matplotlib.pyplot as plt 
import numpy as np 

d = np.random.rand(100, 100) 

fig = plt.figure() 
ax = plt.gca() 
plt.imshow(d) 

# If I comment this I get coordinates in the bottom right, 
# but after setting the ticks I only get "x= y=" 
ax.set_xticks([0, 25, 50, 75, 100]) 
ax.set_xticklabels([0, 0.25, 0.5, 0.75, 1]) 
ax.set_yticks([0, 25, 50, 75, 100]) 
ax.set_yticklabels([0, 0.25, 0.5, 0.75, 1]) 

fig.show() 
raw_input() 

這將顯示數據的隨機地圖和將刻度標籤設置爲從0到1,但右下角的光標座標僅顯示「x = y =」。

是否有任何方法讓座標顯示在由滴答定義的新單位中?我認爲這與設置座標軸的變換有關,但我無法弄清楚。

回答

1

你應該叫 「imshow」 時,使用 「範圍」 的說法:

import matplotlib.pyplot as plt 
import numpy as np 

d = np.random.rand(100, 100) 

fig = plt.figure() 
ax = plt.gca() 
plt.imshow(d, extent=(0,1,1,0)) 

ax.set_xticks([0, 0.25, 0.50, 0.75, 1]) 
ax.set_yticks([0, 0.25, 0.50, 0.75, 1]) 

fig.show() 
raw_input() 
相關問題