Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib imshow() stretch to "fit width"

I've got an image, and a measure associated with each column of its pixels. I'm using pyplot to create a figure with the image on top, and a plot of the column measurements below. I'm using something like this:

import numpy as np import matplotlib.pyplot as plt  A = np.random.rand(34*52).reshape(34,52) means = np.average(A,axis=0)  plt.figure()  plt.subplot(2,1,1) plt.imshow(A, interpolation='nearest' )  plt.subplot(2,1,2) plt.plot(means)  plt.show() 

How can I stretch the image's width to the match that of the plots. That way, when looking at the measurements in the plot, the souce pixels will be in a column directly above it.

like image 217
ajwood Avatar asked Oct 09 '12 18:10

ajwood


People also ask

How do you normalize Imshow?

Just specify vmin=0, vmax=1 . By default, imshow normalizes the data to its min and max. You can control this with either the vmin and vmax arguments or with the norm argument (if you want a non-linear scaling).

What is extent in Imshow?

The extent keyword arguments controls the bounding box in data coordinates that the image will fill specified as (left, right, bottom, top) in data coordinates, the origin keyword argument controls how the image fills that bounding box, and the orientation in the final rendered image is also affected by the axes limits ...


1 Answers

Turns out that it's as simple as giving aspect='auto' to the imshow call.

plt.imshow(A, interpolation='nearest', aspect='auto') 
like image 67
ajwood Avatar answered Sep 22 '22 09:09

ajwood