I am having some trouble using Pyplot imshow to plot an image from a numpy ndarray called data keeping both its aspect ratio and square-shaped pixels. The shape of the ndarray is (112, 2182). Here´s the code I´m using:
import matplotlib as mpl
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
mpl.use('Agg')
import matplotlib.pyplot as plt
data = np.random.random_sample((112, 2182))
plt.figure(figsize=(25, 3.5))
plt.subplots_adjust(left=0.1, right=0.9)
ax = plt.subplot(111)
plt.axis('off')
plt.title('Title', fontweight='bold', y=1.15)
im = ax.imshow(data)
# Add same-width colorbar to the bottom of the image
divider = make_axes_locatable(ax)
cax = divider.append_axes("bottom", size="25%", pad=0.3)
cbar = plt.colorbar(im, orientation="horizontal", cax=cax)
# Save image
plt.savefig('image.pdf', dpi=1000, format=pdf)
I thought that by setting the aspect using the shape of the ndarray the image would show square pixels. However, the image seems to keep the aspect ratio but pixels are not squares, as you can see in zoomed image (I still can´t post images, sorry):
These outputs are the same I got when I used im = ax.imshow(data) withouth the aspect argument. I manually counted pixels in the y-axis of the whole plot and there are 112 of them, so it is not a matter of pixel grouping. Any ideas on how to solve this?
EDIT: the image I am plotting will also have a colorbar and a title. Besides, I need to be able to save it to a pdf file. The zoomed plot I uploaded is a screen capture of the plot zoomed in a pdf viewer.
