First time here? Check out the FAQ!

Ask Your Question
0

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

asked 12 years ago

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!

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

calc314 gravatar image

updated 12 years ago

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.

Preview: (hide)
link
1

answered 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )
0

answered 12 years ago

Erez gravatar image

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

Preview: (hide)
link

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: 12 years ago

Seen: 4,510 times

Last updated: Jun 27 '12