best way to display an imshow() with the correct shape ?

Dear all,

I’ve been trying to plot a ‘pixel’ image of data contained in an array with a given shape. The imshow() func is perfect for this however, the image is usually displayed with margins within a figure. I tried to get rid of this margin to get the axes in full view. However, I never properly got my way around this: the outermost pixels are only partly displayed or there is always a remaining border. I put some code below to show this. Could anyone give me a hint on what I’m doing wrong ? What I need to do, in the end is ‘simply’ to shift the axes by half a pixel left, right and top… I tried doing so by using the axes.set_position() but couldn’t figure out proper values for this.

#build array containing data and set correct shape
data =
np.asarray(datalist)
data = np.reshape(data,(9,41))

#set figure to correct shape
initsize = 10.
width2heightratio = 9./41.
figwidth = initsize
figheight = initsize*width2heightratio
fig = Figure(figwidth ,figheight )

#create axes
axes = fig .gca()

#set to 0,0 pos to get rid of margins
axes1.set_position((0.,0.,1.,1.))

axes.imshow(data,origin=‘upper’)

···

Envoyé avec Yahoo! Mail.
Une boite mail plus intelligente.

Aur� Gourrier wrote:

Dear all,

I've been trying to plot a 'pixel' image of data contained in an array with a given shape. The imshow() func is perfect for this however, the image is usually displayed with margins within a figure. I tried to get rid of this margin to get the axes in full view. However, I never properly got my way around this: the outermost pixels are only partly displayed or there is always a remaining border. I put some code below to show this. Could anyone give me a hint on what I'm doing wrong ? What I need to do, in the end is 'simply' to shift the axes by half a pixel left, right and top... I tried doing so by using the axes.set_position() but couldn't figure out proper values for this.

#build array containing data and set correct shape
data = np.asarray(datalist)
data = np.reshape(data,(9,41))

#set figure to correct shape
initsize = 10.
width2heightratio = 9./41.
figwidth = initsize
figheight = initsize*width2heightratio
fig = Figure(figwidth ,figheight )

#create axes
axes = fig .gca()

#set to 0,0 pos to get rid of margins
axes1.set_position((0.,0.,1.,1.))

axes.imshow(data,origin='upper')

You might try fiddling with fig.subplots_adjust()

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma