Help with Plotting/Saving in Gnuplot

  • Thread starter erok81
  • Start date
  • Tags
    Gnuplot
In summary, to successfully create a gnuplot "macro" lab03.gpl, you need to ensure that your .dat file is in the same directory as your .gpl file, add the command "set term postscript" before the plot command, and use the command "set output 'xxx.ps'" in the gnuplot command line after loading the .gpl file. Make sure you also have the necessary permissions to create and save files in the working directory.
  • #1
erok81
464
0

Homework Statement



Download the file xxx.dat. Create a gnuplot "macro" lab03.gpl which, when loaded by gnuplot will do the following:

- create an output postscript file lab03.ps
- make a plot of the contents of xxx.dat, for x-axis (column 1) values between -0.5 and 3.5 and y-axis (column 2) values between -0.1 and 1.1, in the postscript file.
- reset the gnuplot terminal type to X11.

Homework Equations



None.

The Attempt at a Solution



Here is what I am doing.

I create a .dat with with the above download (which is just two columns of values).

Then I create a .gpl file with the following line: plot [-0.5:3.5] [-0.1:1.1] 'xxx.dat' with lines

After opening gnuplot I type: load "xxx.gpl" and my plot opens fine.

Reading some instructions on saving plots, I then do:

set terminal to postscript
set output "xxx.ps"

Then quit gnuplot.

Lastly I use gv to view my newly created .ps file using: gv xxx.ps. After a few seconds I get an error saying gv cannot open file because there is no data.

Sure enough using ls -l I can my xxx.ps file is 0kb.


Any ideas what I am doing wrong or why this isn't working?
 
Physics news on Phys.org
  • #2




Hello, I am a scientist and I would like to offer some suggestions to help you with your problem. First, make sure that your .dat file is in the same directory as your .gpl file. This will ensure that gnuplot can access the data when you load the .gpl file.

Next, I would recommend adding the command "set term postscript" before the plot command in your .gpl file. This will set the terminal type to postscript and ensure that the output is saved as a postscript file.

Also, instead of using "set output" in your .gpl file, you can use the command "set output 'xxx.ps'" in the gnuplot command line after loading the .gpl file. This will save the output as a postscript file without quitting gnuplot.

Lastly, make sure that you have the necessary permissions to create and save files in the directory where you are working.

I hope these suggestions help and good luck with your plot!
 

1. How do I plot a graph in Gnuplot?

To plot a graph in Gnuplot, you will need to first open the Gnuplot program and enter the data points that you want to plot. Then, use the "plot" command to specify the data points and the plot style you want to use. Finally, use the "set xlabel" and "set ylabel" commands to label your x-axis and y-axis, respectively. Once you have entered all the necessary commands, use the "show plot" command to display the graph.

2. How do I save a plot in Gnuplot?

To save a plot in Gnuplot, use the "set term" command to specify the output format, such as "png" or "pdf". Then, use the "set output" command to specify the filename and location where you want to save the plot. Finally, use the "replot" command to redraw the graph and save it in the specified format.

3. How do I change the style of my plot in Gnuplot?

To change the style of your plot in Gnuplot, use the "plot" command and specify the plot style you want to use, such as "lines", "points", or "linespoints". You can also customize the style further by using options like color, line width, and point size. Alternatively, you can use the "set style" command to set a default plot style for all subsequent plots.

4. How do I plot multiple data sets on the same graph in Gnuplot?

To plot multiple data sets on the same graph in Gnuplot, use the "plot" command and specify the data points for each data set, separated by commas. You can also use the "title" option to label each data set. Alternatively, you can use the "multiplot" command to create a grid of plots, each with its own set of data points.

5. How do I add a legend to my plot in Gnuplot?

To add a legend to your plot in Gnuplot, use the "set key" command and specify the position, text font, and other options for the legend. Then, use the "title" option in the "plot" command to label each data set in the legend. You can also customize the appearance of the legend further by using options like color and line style.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
4K
  • Programming and Computer Science
Replies
5
Views
6K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
4
Views
7K
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top