I am using matplotlib table to create a heatmap that contains different values. While creating the table, ticks are not aligned at the center of each cell in both x-axis and y-axis.
I want to create something like this.

But rather I am getting ticks that are not uniform in both axes. Ticks starts at the middle of the cell from bottom-left column and gets distorted while moving to top and right cell.

I am using this code to generate this matplotlip table.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import os
import sys
from matplotlib.table import Table
fig,ax=plt.subplots(figsize=(15,15))
tb = Table(ax,bbox=[0,0,1,1])
nrows, ncols = 20,20
width, height = 1.0 / ncols, 1.0 / nrows
headers = 20
data = np.zeros((nrows, ncols))
ax.set_xticks(np.arange(0.5,headers+0.5))
ax.set_yticks(np.arange(0.5,headers+0.5))
ax.xaxis.set_tick_params(labelsize=12)
ax.yaxis.set_tick_params(labelsize=12)
for (i,j),val in np.ndenumerate(data):
tb.add_cell(i, j, width, height)
tb.add_cell(i, j, width, height, loc='center')
tb.auto_set_font_size(False)
tb.set_fontsize(15)
ax.add_table(tb)
ax.set_aspect('equal')
plt.show()
Is there anything I am missing?


