2015-04-03 33 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() 
相关问题