Hello everyone,
I have a problem. I have to look at many plots. Usely I do it like that:
from pylab import*
X1 = genfromtxt("Myfile.dat", usecols =(0))
Y1 = genfromtxt("Myfile.dat", usecols =(1))
plot(X1,Y1, label ="My curve")
show()
But the problem is when I have many plots I have to copy paste and
change manually all the name of the variables X1, X2, X3...etc. It's
not really convenient.
I want to create a def with the name of my file as argument which do
something like that:
from pylab import*
def plotgraph(name):
X_name = genfromtxt("name", usecols =(0))
Y_name = genfromtxt("name", usecols =(1))
plot(X_name,Y_name, label ="name")
plotgraph(MyFile)
show()
But it doesn't work. Do you know why? Do you have a smarter idea?
Thanks!
Fab
Dear Fabien
2012/5/29 Fabien Lafont <lafont.fabien@...287...>:
Hello everyone,
I have a problem. I have to look at many plots. Usely I do it like that:
from pylab import*
X1 = genfromtxt("Myfile.dat", usecols =(0))
Y1 = genfromtxt("Myfile.dat", usecols =(1))
plot(X1,Y1, label ="My curve")
show()
But the problem is when I have many plots I have to copy paste and
change manually all the name of the variables X1, X2, X3...etc. It's
not really convenient.
I want to create a def with the name of my file as argument which do
something like that:
from pylab import*
def plotgraph(name):
X_name = genfromtxt("name", usecols =(0))
Y_name = genfromtxt("name", usecols =(1))
plot(X_name,Y_name, label ="name")
plotgraph(MyFile)
show()
Try this:
def plotgraph(name):
"""Plot stuff:
name: string
file name
"""
X_name, Y_name = genfromtxt(name, usecols =(0,1)).T
plot(X_name,Y_name, label =name)
'name' should contain already a string, so you have to pass it to
genfromtxt. I you pass "name", the file name is "name" and not the
what is in the variable.
Just a note: if you read the file as 'X_name, Y_name =
genfromtxt(name, usecols =(0,1)).T' you open, read and close the file
only once.
Cheers,
Francesco
···
But it doesn't work. Do you know why? Do you have a smarter idea?
Thanks!
Fab
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
--
personals: montyfra@...174..., monte_fra@...32... (messenger),
franz.bergesund@...3264...
work: montefra@...2911...
http://picasaweb.google.it/franz.bergesund
Thx Francesco, it works great!
What for the .T at the end of genfromtxt?
2012/5/29 Francesco Montesano <franz.bergesund@...982...>:
···
Dear Fabien
2012/5/29 Fabien Lafont <lafont.fabien@...287...>:
Hello everyone,
I have a problem. I have to look at many plots. Usely I do it like that:
from pylab import*
X1 = genfromtxt("Myfile.dat", usecols =(0))
Y1 = genfromtxt("Myfile.dat", usecols =(1))
plot(X1,Y1, label ="My curve")
show()
But the problem is when I have many plots I have to copy paste and
change manually all the name of the variables X1, X2, X3...etc. It's
not really convenient.
I want to create a def with the name of my file as argument which do
something like that:
from pylab import*
def plotgraph(name):
X_name = genfromtxt("name", usecols =(0))
Y_name = genfromtxt("name", usecols =(1))
plot(X_name,Y_name, label ="name")
plotgraph(MyFile)
show()
Try this:
def plotgraph(name):
"""Plot stuff:
name: string
file name
"""
X_name, Y_name = genfromtxt(name, usecols =(0,1)).T
plot(X_name,Y_name, label =name)
'name' should contain already a string, so you have to pass it to
genfromtxt. I you pass "name", the file name is "name" and not the
what is in the variable.
Just a note: if you read the file as 'X_name, Y_name =
genfromtxt(name, usecols =(0,1)).T' you open, read and close the file
only once.
Cheers,
Francesco
But it doesn't work. Do you know why? Do you have a smarter idea?
Thanks!
Fab
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
--
personals: montyfra@...174..., monte_fra@...32... (messenger),
franz.bergesund@...3264...
work: montefra@...2911...
http://picasaweb.google.it/franz.bergesund
2012/5/29 Fabien Lafont <lafont.fabien@...287...>:
Thx Francesco, it works great!
What for the .T at the end of genfromtxt?
genfromtxt with usecols=(0,1) return an array with 2 columns. with .T
you transpose it so that you can save it in two variables. For more
info, e.g., numpy.ndarray.T — NumPy v1.26 Manual
Cheers,
Francesco
···
2012/5/29 Francesco Montesano <franz.bergesund@...982...>:
Dear Fabien
2012/5/29 Fabien Lafont <lafont.fabien@...287...>:
Hello everyone,
I have a problem. I have to look at many plots. Usely I do it like that:
from pylab import*
X1 = genfromtxt("Myfile.dat", usecols =(0))
Y1 = genfromtxt("Myfile.dat", usecols =(1))
plot(X1,Y1, label ="My curve")
show()
But the problem is when I have many plots I have to copy paste and
change manually all the name of the variables X1, X2, X3...etc. It's
not really convenient.
I want to create a def with the name of my file as argument which do
something like that:
from pylab import*
def plotgraph(name):
X_name = genfromtxt("name", usecols =(0))
Y_name = genfromtxt("name", usecols =(1))
plot(X_name,Y_name, label ="name")
plotgraph(MyFile)
show()
Try this:
def plotgraph(name):
"""Plot stuff:
name: string
file name
"""
X_name, Y_name = genfromtxt(name, usecols =(0,1)).T
plot(X_name,Y_name, label =name)
'name' should contain already a string, so you have to pass it to
genfromtxt. I you pass "name", the file name is "name" and not the
what is in the variable.
Just a note: if you read the file as 'X_name, Y_name =
genfromtxt(name, usecols =(0,1)).T' you open, read and close the file
only once.
Cheers,
Francesco
But it doesn't work. Do you know why? Do you have a smarter idea?
Thanks!
Fab
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
--
personals: montyfra@...174..., monte_fra@...32... (messenger),
franz.bergesund@...3264...
work: montefra@...2911...
http://picasaweb.google.it/franz.bergesund
--
personals: montyfra@...174..., monte_fra@...32... (messenger),
franz.bergesund@...3264...
work: montefra@...2911...
http://picasaweb.google.it/franz.bergesund