2015-04-03 76 views
0

的中間使蜱下面的代碼生成一個矩陣圖即它的每一平方索引與從1號的中間至39:matshow python中與盤區,在正方形

import numpy as np 
from matplotlib import pyplot as plt 
a=np.random.uniform(0,1,1600).reshape((40,40)) 
fig, ax = plt.subplots(1,1) 
ax.matshow(a, vmin = 0, vmax = 1, interpolation = 'none') 
label_list=np.arange(0,40,5) 
label_list=np.append(label_list,39) 
ax.set_xticks(label_list) 
ax.set_yticks(label_list) 
plt.show() 

enter image description here

當我想要將數字更改爲01.95或基本上[0,39]*0.05時,標籤縮小到軸的起點。如果我嘗試在matshow中使用範圍,那麼標籤不會指向正方形的中間位置!我怎樣才能使這個浮動指數指向廣場的中間?

+1

更改標籤而不更改標記。 – cphlewis 2015-04-03 20:27:59

+0

這似乎工作!謝謝! – Cupitor 2015-04-03 20:30:38

回答

2
import numpy as np 
from matplotlib import pyplot as plt 

a=np.random.uniform(0,1,1600).reshape((40,40)) 
fig, ax = plt.subplots(1,1) 
ax.matshow(a, vmin = 0, vmax = 1, interpolation = 'none') 
tick_list = np.append(np.arange(0,40,5), 39) 
label_list=map(lambda x: str(0.05*x), tick_list) 
ax.set_xticks(tick_list) 
ax.set_xticklabels(label_list) 
ax.set_yticks(tick_list) 
ax.set_yticklabels(label_list) 
plt.show() 
相關問題