[Tutor] plotting in python

stm atoc stm.at.oc at googlemail.com
Wed Nov 30 22:08:52 CET 2011


Hi there,

I have a question regarding plotting with Python.

I have the following python script:

# coding: utf-8
from pylab import *
import numpy

filename='ourtest_out.list'

fh=open(filename)
line=fh.readline()
fh.close

z=array([ float(val) for val in line.split()[1:] ])


a = numpy.loadtxt(filename,skiprows=3)
N=100
t = a[:,0]
nu = a[0:,1:N+1]
#Conc = a[1:,N+1:]
Conc = a[1:,N+1:]

levels=arange(-10,1)
levels=levels[-3]-levels
t=t/360.

figure()
plot(Conc[0],z)

xlabel('C')
ylabel('z')
#show()
savefig('Conc.png')
close()

#########nu
figure()
lw = 2.0 #linewidth
dpi = 96

levels=arange(-10,1)
levels=levels[-3]-levels
plot(nu[0],z)
xlabel('nu')
ylabel('z')
savefig('nu.png')
close()


--------However, once I run the program (run.py)

I have error like this:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/…./run.py in <module>()
     24
     25 figure()
---> 26 plot(Conc[0],z)
     27
     28 xlabel('C')

/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/pyplot.py
in plot(*args, **kwargs)
   2284         ax.hold(hold)
   2285     try:
-> 2286         ret = ax.plot(*args, **kwargs)
   2287         draw_if_interactive()
   2288     finally:

/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py
in plot(self, *args, **kwargs)
   3781         lines = []
   3782
-> 3783         for line in self._get_lines(*args, **kwargs):
   3784             self.add_line(line)
   3785             lines.append(line)

/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py
in _grab_next_args(self, *args, **kwargs)
    315                 return
    316             if len(remaining) <= 3:
--> 317                 for seg in self._plot_args(remaining, kwargs):
    318                     yield seg
    319                 return

/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py
in _plot_args(self, tup, kwargs)
    292             x = np.arange(y.shape[0], dtype=float)
    293
--> 294         x, y = self._xy_from_xy(x, y)
    295
    296         if self.command == 'plot':

/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py
in _xy_from_xy(self, x, y)
    232         y = np.atleast_1d(y)
    233         if x.shape[0] != y.shape[0]:
--> 234             raise ValueError("x and y must have same first dimension")
    235         if x.ndim > 2 or y.ndim > 2:
    236             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension


-------So, What would you suggest?
Thanks in advance,
Sue


More information about the Tutor mailing list