Loading txt files

Hi!
I'm new at Matplotlib, so I need a little help.
I was trying to load data from txt files with no luck.
I have 2 collumns in txt files and I need to plot a XY graph. Should I
modify txt file to other format?

Can someone give me a simple example for doing this?

In txt file could be such information:
Meters Seconds
1 4
2 8
3 12
4 16
5 20

Thanks in advance!

···

--
View this message in context: http://old.nabble.com/Loading-txt-files-tp32758393p32758393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

One quick way of doing this is to use numpy:

import numpy

dataset = numpy.genfromtxt(fname='yourfilename',skip_header=1)

http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html

···

On Tue, Nov 1, 2011 at 8:50 AM, yelena <somebody_@...3831...> wrote:

Hi!
I'm new at Matplotlib, so I need a little help.
I was trying to load data from txt files with no luck.
I have 2 collumns in txt files and I need to plot a XY graph. Should I
modify txt file to other format?

Can someone give me a simple example for doing this?

In txt file could be such information:
Meters Seconds
1 4
2 8
3 12
4 16
5 20

Thanks in advance!

--
View this message in context: http://old.nabble.com/Loading-txt-files-tp32758393p32758393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Daniel Hyams
dhyams@...287...

I have numpy.
I need the body of a program, which plots y dependence of x.

Maybe than I'll figure out how does it works...

Daniel Hyams wrote:

···

One quick way of doing this is to use numpy:

import numpy

dataset = numpy.genfromtxt(fname='yourfilename',skip_header=1)

numpy.genfromtxt — NumPy v1.26 Manual

On Tue, Nov 1, 2011 at 8:50 AM, yelena <somebody_@...3831...> wrote:

Hi!
I'm new at Matplotlib, so I need a little help.
I was trying to load data from txt files with no luck.
I have 2 collumns in txt files and I need to plot a XY graph. Should I
modify txt file to other format?

Can someone give me a simple example for doing this?

In txt file could be such information:
Meters Seconds
1 4
2 8
3 12
4 16
5 20

Thanks in advance!

--
View this message in context:
http://old.nabble.com/Loading-txt-files-tp32758393p32758393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Daniel Hyams
dhyams@...287...

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/Loading-txt-files-tp32758393p32758620.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Attached is a very simple version.
It assumes your sample data is in a file.

The first line is "magic" and makes significant assumptions about where python is installed on your system. This may or may not be the right answer for your system.

Plotting requires matplotlib which you may need to install.

···

------------
#!/sw/bin/python

import numpy
import matplotlib.pyplot as plt

dataset = numpy.genfromtxt(fname='readata.txt',skip_header=1)

print dataset

x=dataset[:,0]
y=dataset[:,1]

plt.figure(1)
plt.plot(x,y)
plt.plot(x,y,'ro')
plt.show()
--------------

On Nov 1, 2011, at 9:29 , yelena wrote:

I have numpy.
I need the body of a program, which plots y dependence of x.

Maybe than I'll figure out how does it works...

Daniel Hyams wrote:

One quick way of doing this is to use numpy:

import numpy

dataset = numpy.genfromtxt(fname='yourfilename',skip_header=1)

numpy.genfromtxt — NumPy v1.26 Manual

On Tue, Nov 1, 2011 at 8:50 AM, yelena <somebody_@...3831...> wrote:

Hi!
I'm new at Matplotlib, so I need a little help.
I was trying to load data from txt files with no luck.
I have 2 collumns in txt files and I need to plot a XY graph. Should I
modify txt file to other format?

Can someone give me a simple example for doing this?

In txt file could be such information:
Meters Seconds
1 4
2 8
3 12
4 16
5 20

Thanks in advance!

--
View this message in context:
http://old.nabble.com/Loading-txt-files-tp32758393p32758393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Daniel Hyams
dhyams@...287...

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/Loading-txt-files-tp32758393p32758620.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

It works!
Thank you very much! :slight_smile:

Dale Chayes wrote:

···

Attached is a very simple version.
It assumes your sample data is in a file.

The first line is "magic" and makes significant assumptions about where
python is installed on your system. This may or may not be the right
answer for your system.

Plotting requires matplotlib which you may need to install.

------------
#!/sw/bin/python

import numpy
import matplotlib.pyplot as plt

dataset = numpy.genfromtxt(fname='readata.txt',skip_header=1)

print dataset

x=dataset[:,0]
y=dataset[:,1]

plt.figure(1)
plt.plot(x,y)
plt.plot(x,y,'ro')
plt.show()
--------------

On Nov 1, 2011, at 9:29 , yelena wrote:

I have numpy.
I need the body of a program, which plots y dependence of x.

Maybe than I'll figure out how does it works...

Daniel Hyams wrote:

One quick way of doing this is to use numpy:

import numpy

dataset = numpy.genfromtxt(fname='yourfilename',skip_header=1)

numpy.genfromtxt — NumPy v1.26 Manual

On Tue, Nov 1, 2011 at 8:50 AM, yelena <somebody_@...3831...> wrote:

Hi!
I'm new at Matplotlib, so I need a little help.
I was trying to load data from txt files with no luck.
I have 2 collumns in txt files and I need to plot a XY graph. Should I
modify txt file to other format?

Can someone give me a simple example for doing this?

In txt file could be such information:
Meters Seconds
1 4
2 8
3 12
4 16
5 20

Thanks in advance!

--
View this message in context:
http://old.nabble.com/Loading-txt-files-tp32758393p32758393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Daniel Hyams
dhyams@...287...

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context:
http://old.nabble.com/Loading-txt-files-tp32758393p32758620.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save &#36;700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://old.nabble.com/Loading-txt-files-tp32758393p32765442.html
Sent from the matplotlib - users mailing list archive at Nabble.com.