This script fixes the problem described in: https://tex.stackexchange.com/questions/445977/pgfplots-matrix-plot-perfect-rectangles
The script needs pdftk
to be available on the path.
Then you can run it with:
$ python fix_figure.py -i input_file.pdf -o fixed_file.pdf