Save data to text file - List_plot(...).save(Path, Name..)?

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

Hey,

Is there a way to save data in list plot as a text file in stead/ in addition to showing it with .show() ?

In this way - I want to export the data from my list, say to Excel or Matlab in order to plot it using their tools. I wish the data would be arrange in the text file in a list of values that I could then copy (for example) to the Excel table.

Thanking u on advance!

asked Jun 25 '12

anonymous user

Anonymous

3 Answers:

i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

You can use the Data Menue

DATA is an environment variable: path to the attached files of the respective worksheet.

L = [0..10]
out = file(DATA+'mydata.txt','w')
for k in L:
    out.write(str(k)+'\n')
out.close()
list_plot(L).save(DATA+'myplot.png')

The files should appear in the list of Data files.

link

posted Jun 25 '12

ndomes gravatar image ndomes
536 7 16

O.K, thanks! - Where do I see the list of data files, and are they in a format that I could export to other program, such as an Excel table, or as a *.png? What is the meaning of the two different 'out's - before and inside the loop? The out.close() is used because of the loop?

Erez (Jun 25 '12)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

Another option is the use the csv package in python. You can write using this as follows. In the snippet below, info is a list of lists containing data that you want to write to a file.

import csv
info=[[1,2,3],[4,5,6]]
writefile = csv.writer(open(DATA+'myfile.csv', 'w'))
for i in range(0,len(info)): 
      writefile.writerow(info[i])

This will result in a .csv file that Excel can read.

link

posted Jun 25 '12

calc314 gravatar image calc314
1820 3 19 51

updated Jun 25 '12

i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Thx both! Eventually I tried more or less both ways and it worked, I used the txt file.

link

posted Jun 27 '12

Erez gravatar image Erez
1 4

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

3 followers

Tags:

Stats:

Asked: Jun 25 '12

Seen: 185 times

Last updated: Jun 27 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.