Ask Your Question
0

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

asked 2012-06-25 04:42:16 +0100

anonymous user

Anonymous

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!

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-06-25 16:05:43 +0100

calc314 gravatar image

updated 2012-06-25 16:08:16 +0100

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.

edit flag offensive delete link more
1

answered 2012-06-25 07:34:46 +0100

ndomes gravatar image

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.

edit flag offensive delete link more

Comments

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 gravatar imageErez ( 2012-06-25 08:16:46 +0100 )edit
0

answered 2012-06-27 06:18:05 +0100

Erez gravatar image

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2012-06-25 04:42:16 +0100

Seen: 4,421 times

Last updated: Jun 27 '12