Hello All you Lovely People on stackoverflow,
I am trying to plot data using gnuplot. I start by reading through a table and pulling out the data I want. I write this data to a .dat file. As of now, I’m just trying to plot it through a command line but will add the necessary code to plot it from the python script after it’s working.
My code which creates the .dat file-
#!/usr/bin/python
file = open("test_m.rdb")
table = open('table.dat', 'w+')
trash = file.readline()
trash = file.readline()
data = file.readline()
i = data.split()
flux = i[2]
observed = i[4]
table.write(flux + " " + observed,)
while 1:
line = file.readline()
i = line.split()
try:
flux = i[2]
observed = i[4]
except IndexError:
break
table.write("\n" + flux + " " + observed)
table.close()
The command I’m attempting to use in cygwin and the error-
gnuplot plot table.dat
0.058 2
^
"table.dat", line 1: invalid command
Thank you in advance. I appreciate any suggestions you can offer.
you probably want:
With your command, gnuplot is looking for commands to run in a file called ‘plot’ and then in a file called ‘table.dat’. ‘table.dat’ doesn’t have commands to run, it has data to be plotted. using ‘-e’ is the same thing as putting the stuff in singe quotes into a temporary file (call it temp.gp) and then doing
gnuplot temp.gp. The--persistmakes it so the plot stays on your screen (which you’ll want since I doubt you’re saving it to a file). To learn about how to save it to a file, inside gnuplot do:help set termandhelp set outputandset term.EDIT
I don’t know much about cygwin, so I don’t know what the default terminal is (or what terminals will be enabled).
A few things to try:
Put the commands in a file
Now run it:
and then open the postscript using whatever tool you have for viewing postscripts — I often use
gv, but I don’t know what there is on cygwin.