2

I am trying to plot some data with the plotfile function of matplotlib, i.e.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from matplotlib.pyplot import *
from numpy import *

x = arange(0,10,0.001)
y = sin(x)
savetxt("test.dat",column_stack((x,y)))

plotfile("test.dat",(0,))
show()

this gives me the following error

ValueError: invalid literal for float(): 1.000000000000000021e-03 9.99999833333341681

using the genfromtxt() function works perfect with the generated data so I don't see why there should be an error. Thank you for your help.

1 Answer 1

1

By default numpy.savetxt uses a single space as the column delimiter.

However, the default delimiter for matplotlib.pyplot.plotfile is a comma.

One way to fix is to specify a comma as the column-delimiter in your call to savetxt, e.g.:

import numpy as np 
np.savetxt("test.dat", np.column_stack((x, y)), delimiter=',')
Sign up to request clarification or add additional context in comments.

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.