Hi Karthik,
I cannot find any problem with your code. You are mixing modules a little
too much to my taste but it's not a technical problem.
Loading and saving the data works flawless here. Attached is an infile and a
modified script, please try this.
2011/6/11 Karthikraja Velmurugan <velmurugan.karthikr...@gmail.com>
> *Hi Daniel, *
> * *
> *I used the code but there is small issue. I forgot to mention that my
> values are signed and unsigned decimal values. *
> *My values look like this
> *
> 0.0023 -0.0456 0.0419 0.094 -0.0004 0.0236 -0.0237 -0.0043 -0.0718
> 0.0095 0.0592 -0.0417 0.0023 0.0386 -0.0023 -0.0236 -0.1045 0.098
> -0.0006 0.0516 0.0463 -0.0035 -0.0442 0.1371 0.022 -0.0222 0.256 0.4903
> 0.0662 -0.0763 0.0064 0.1404
>
> *After running the code the "pylab.savetxt" saves the same data something
> like this*
>
>
> 8.205965840870644800e-01;8.034591567160346300e-01;5.493847743502982000e-01;2.581157685701491700e-01;6.409997826977161800e-01;3.719908502347885100e-01
>
I assume you are confused about the many decimals. Whenever floats are
processed by Python they are real floats, see here:
http://docs.python.org/release/2.5.2/tut/node16.html
To me, it looks as if you have truncated the lines, but otherwise there is
nothing wrong...
*When I tried to extract data and print them they look like this (totally
> different from the actual values!)*
>
> [ 0.18353712 0.30468928 0.16164556 ..., 0.98860032 0.49681098
> 0.77393306]
>
Yes, these are different numbers. But I assume you are comparing different
rows or columns?!
> *When I tried not using the "pylab.savetxt" function it gives an error
> like below:*
>
> ValueError: invalid literal for float():
> 0.0023,-0.0456,0.0419,0.094,0.0224,0.0365
>
This error message tells you that you are trying to save non-numeric data to
a file with that command.
Eg. this will cause the same error: scipy.savetxt('asdfasdf.dat',
'asdfasdf')
It is *VERY* hard to tell what you are doing since you don't provide exact
pieces of code.
> *Is there a specific way to handle signed decimal number? If so please
> suggest some changes.* And also I did try using the "array[]" to access
> individual comulns but I get an error saying the numpy.ndarray object not
> callable.
>
I must ask again? Have you played with the examples that I provided? You are
using the function in a wrong way (again, I can't tell for sure since you
don't provide code):
In order to acces the first row from a data array, you simply use data[0],
the first column is data.T[0].
*import matplotlib.pyplot as plt
> import pylab
> import scipy
> import numpy
> datafile1 = 'vet1.csv'
> data = pylab.rand(98760,6)
> pylab.savetxt(datafile1, data, delimiter=';')
> a1 = pylab.loadtxt(datafile1, comments='#', delimiter=';').T
> print 'loading', datafile1
> v1 = [0,1]
> v2 = [-2,2]*
> *plt.close('all')
> plt.figure()*
> *plt.ylim(v2)
> for i in range(2):
> plt.plot(a1[i])*
> *plt.show()*
>
> -Karthik
>
Please do provide all steps that cause problems, not just the results. It is
impossible to help you with assumptions and guesses :)
Best regards,
Daniel
0.0023;-0.0456;0.0419;0.094
-0.0004;0.0236;-0.0237;-0.0043
-0.0718;0.0095;0.0592;-0.0417
0.0023;0.0386;-0.0023;-0.0236
-0.1045;0.098;-0.0006;0.0516
0.0463;-0.0035;-0.0442;0.1371
0.022;-0.0222;0.256;0.4903
0.0662;-0.0763;0.0064;0.1404
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 11 10:06:55 2011
@author: -
"""
import matplotlib as mpl
## loading both pylab and mpl.pyplot is a little redundant
#import matplotlib.pyplot as plt
import pylab
import scipy
## don't need numpy when you have scipy already :)
#import numpy
data = pylab.rand(98760,6)
'''
pylab offers many functions from scipy in order to simplify daily tasks.
however, when doing more complex stuff where scipy/numpy is required,
it's probably better to use it consistently.
'''
data = scipy.rand(98760,6)
data = scipy.rand(5,4)
print data ## looks totally OK to me
data = scipy.loadtxt('karthikIN.csv', delimiter=';')
print data ## also OK
datafile1 = 'vet1.csv'
pylab.savetxt(datafile1, data, delimiter=';')
print 'loading', datafile1
## don't transpose here in order to compare with infile:
a1 = pylab.loadtxt(datafile1, comments='#', delimiter=';')#.T
print a1 ## again, this is totally OK and as expected
print a1 == data
pylab.close('all')
v1 = [0,1]
v2 = [-2,2]
pylab.figure()
pylab.ylim(v2)
for i in range(2):
pylab.plot(a1[i])
pylab.show()
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users