Autoscaling imagesc plot and imshow plots

Matlab / GNU Octave default axis scaling scales “x” and “y” axes proportionally to the axes values. If one axis values span a much wider range than the other axis, the smaller span axis gets very thin and almost invisible.

Fix invisible axis in plot by axis('square') after imagesc()

rdat = rand(1000,10);
imagesc(rdat)

axis('square')

Axes representing actual data size has the axes to be representative of number of data elements (skinny images appear skinny)–insert axis('equal') after imagesc().

rdat = rand(1000,10);
imagesc(rdat)

axis('equal')

In Python Matplotlib, the same issue can be overcome with aspect='auto' property of ax.imshow().

You can conversely allow the “true” axes ratio driven by the actual data aspect='equal'

Set this after the plot is created in axes ax by

import numpy as np
from matplotlib.figure import Figure

rdat = np.random.rand(1000,10)

fg = Figure()
ax = fg.gca()
ax.imshow(rdat)

# %% pick ONE of the following

# non-shared axes
ax.set_aspect('equal','box')

# shared axes only (e.g. subplots(sharex=True))
ax.set_aspect('equal','box-forced')

fg.savefig("example.png")