1

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?


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:

Using PyLab to create a 2D graph from two separate lists

1
  • Where are the dates in your matplotlib calls? And maybe you could reformat this. Commented Apr 23, 2010 at 16:01

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.