tags:

views:

297

answers:

3

Hey Guys,

I'm trying to do a basic line graph here, but I can't seem to figure out how to adjust my x axis.

And here is the error I get when I try adjusting my range.

from pylab import *

plot ( range(0,11),[9,4,5,2,3,5,7,12,2,3],'.-',label='sample1' )
plot ( range(0,11),[12,5,33,2,4,5,3,3,22,10],'o-',label='sample2' )
xlabel('x axis')
ylabel('y axis')
title('my sample graphs')
legend(('sample1','sample2'))
savefig("sampleg.png",dpi=(640/8))

show()


File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 228, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension  

I want my range to be a list of strings: ["12/1/2007","12/1/2008", "12/1/2009","12/1/2010"]

Any suggestions?

+2  A: 

range(0,11) should be range(0,10).

Steve
... or just `range(10)`.
Andrew Jaffe
+1  A: 

In addition to Steve's observation: If your points are always some y-value at the same consecutive integer x's, matplotlib makes the range even implicit.

plot([9,4,5,2,3,5,7,12,2,3],'.-',label='sample1')
honk
Yes, much easier.
Steve
A: 

Honestly, I found the code online and was trying to rewrite it to properly understand it. I think I'm going to start from scratch so that I know what I'm doing but I need help on where to start.

I posted another question which explains what I want to do here:

http://stackoverflow.com/questions/2722216/using-pylab-to-create-a-2d-graph-from-two-separate-lists

Thank you guys for your help.