python 中的 matshow,其范围在正方形中间打勾

matshow in python with extents that make ticks in the middle of squares

以下代码生成一个矩阵图,它的每个正方形都在中间用 1 到 39 之间的数字进行索引:

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()

当我想将数字更改为 01.95 之间或基本上 [0,39]*0.05 时,标签会收缩到轴的开头。如果我尝试在 matshow 中使用范围,那么标签不会指向正方形的中间!我怎样才能使这个浮动索引指向正方形的中间?

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()