falidoro
falidoro

Reputation: 399

Change axes in matplotlib.pyplot.imshow while retaining aspect ratio

I have data stored in a 1000x1000 matrix that I plot using plt.imshow(), resulting in the following image:

However, the y-axis are supposed to range from 0 to 300 and the x-axis from 0 to 1. I've tried using 'extent=[0,1,0,300]', but this results in the following:

enter image description here

I am wondering how I can adjust the values on the axes while retaining the 1:1 aspect-ratio (this is to create a Hovmöller plot, so the y-axis is unrelated to space).

plt.figure(1)
plt.imshow(phi.T, extent=[0,1,0,300], origin='lower')
cbar = plt.colorbar()
plt.show()

Upvotes: 0

Views: 1362

Answers (1)

TSB
TSB

Reputation: 238

plt.imshow(phi.T, extent=[0,1,0,300], aspect=1/300) should do it

Upvotes: 1

Related Questions