Thx Francesco, it works great!

What for the .T at the end of genfromtxt?



2012/5/29 Francesco Montesano <franz.berges...@googlemail.com>:
> Dear Fabien
>
> 2012/5/29 Fabien Lafont <lafont.fab...@gmail.com>:
>> 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
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
> --
> personals: monty...@yahoo.it, monte_...@hotmail.com (messenger),
> franz.berges...@googlemail.com.
> work: monte...@mpe.mpg.de
>
> http://picasaweb.google.it/franz.bergesund

------------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to