1

Suppose I have:

x = ['1.34511','0.0234','-0.0890'] 
y = ['0.0987', '0.8763', '-0.0762']

How can I plot those values in matplotlib? I've already made a search about 'ticks', but I still don't understand...

1 Answer 1

3

edit:

My matplotlib 1.2 can plot the string lists fine btw, there is no need for conversion to begin with, just plot them as they are.

You can first convert them to a float32 Numpy array:

x = ['1.34511','0.0234','-0.0890'] 
y = ['0.0987', '0.8763', '-0.0762']

x = np.array(x, dtype=np.float32)
y = np.array(y, dtype=np.float32)

plt.plot(x,y)

Or use list comprehension to convert the values to a float:

x = ['1.34511','0.0234','-0.0890'] 
y = ['0.0987', '0.8763', '-0.0762']

x = [float(val) for val in x]
y = [float(val) for val in y]

plt.plot(x,y)

enter image description here

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

1 Comment

You might use x=map(float,x) instead of list comprehension.

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.