This is my code i want to display a square matrix with yticklabels in the center of each cell but top and bottom row are trimmed. How to avoid this?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
n=10
mat = np.random.randint(0, 1000, size=(n, n))
classes = ['A','B', 'C', 'D', 'E' ,'F' ,'G', 'H', 'I', 'J']
df = pd.DataFrame(mat, columns=classes, index=classes)
fig = plt.figure()
ax = plt.gca()
im = ax.matshow(df, interpolation='none')
fig.colorbar(im)
ax.set_xticks(np.arange(n))
ax.set_xticklabels(classes)
ax.set_yticks(np.arange(n))
ax.set_yticklabels(classes)
for (i,j), z in np.ndenumerate(df):
ax.text(j, i, str(z), ha="center", va="center")
ax.set_title("Matrix")
plt.show()