Drawing a surface with matplotlib

Monnin yaguarovi at gmail.com
Thu Jan 14 12:14:17 EST 2010


Hello,
I have a newbie question about using matplotlib
I would like to draw the surface defined by the lists X, Y and the
matrix Z.
I get to a nice graphical output with the following code.
My problem is that the labels on the axes indicate values
corresponding to the indices in Tables X and Y.
I would like to see these values between xmin and xmax, ymin and ymax.
If I uncomment the lines set_xlim and set_ylim, the axes are properly
represented, but the picture is squashed into a corner.
How have the values on the axes and correct the image full screen?
Thank you in advance.

#! /usr/bin/env python

from pylab import *

x=[0,1,2,3]
y=[12, 32,81]
z=[2,3,1,4,2,5,6,8,10,4,11,3]
Z=zeros((len(x),len(y)))
count=0
for i in range(0,len(x)):
    for j in range(0,len(y)):
        Z[i,j]=z[count]
        count=count+1

ax = subplot(111)

im = imshow(Z,  interpolation='bilinear')
xmin=x[0]
xmax=x[len(x)-1]
ymin=y[0]
ymax=y[len(y)-1]

#ax.set_xlim(xmin,xmax)
#ax.set_ylim(ymin,ymax)
#axes().set_aspect('auto',adjustable='box')

colorbar()

show()



More information about the Python-list mailing list