I have noticed a frustrating problem with Pythons Matplotlib where matrix plotting produces an uneven grid. This issue is persistent with and without high DPI, as well as in EPS files.
The following code is used for the image generation:
import matplotlib.pyplot as plt
import numpy as np
arr = np.zeros((200,200))
# Set the diagonal to 1
arr[np.arange(200), np.arange(200)] = 1
plt.matshow(arr)
plt.savefig('matshow_test.png', dpi=1000)
DPI=1000:

Which has the sizes 65x65, 90x90, 95x95, 90x90, 95x95 and so on.
DPI=default

Which varies between 1x1 and 2x2 for each cell.
EPS rendered in latex:

Which is clearly distorted.
My questions are:
- Why is this the default behaviour of Matplotlib?
- How can I fix this?
Using Python 3.9.10 with Matplotlib 3.5.1