0

I have a directory inside which there are 10 sub-directories called run1, run2, ...,run10. A programme, say a.f95 is run inside each of these 10 sub-directories. There is some random number inside each version and we are doing 10 runs of the code to compare some results. By running a.f95 10 times inside each of the run1, run2, ... folders, I get 30 data files inside each subdirectory. I need to plot these 30x10 data files and compare the plots to find some pattern. So, it is not possible for me to do this by hand.

We know that the resolution of plots in the interactive qt terminal is much better than that of saved pdf from pdfcairo. I cannot save each qt plot by clicking on the 'save' button in each qt window. I need vector plots from the data, of the sort given below. The top one has been saved as png from qt output window. The bottom one has been obtained by using pngcairo.

png saved from qt window

png version obtained using pngcairoenter image description here

My question is,

  1. How can I save in high resolution, i.e. qt like, plots from the command line in vector graphics format (PDF)? I also need good resolution PNG images for creating animation of evolution.
  2. How do I save 30 gnuplot plots inside each run* subdirectory from the terminal, using, preferably, a bash script?

Any suggestion would be highly appreciated. Thank you.

I have generated the png output using

set term pngcairo
set size square
p 'data_fl.400.dat' u 3:4:5:6 w vec

Edit 1:In each subdirectory run* (eg. run1, run2, ...) the data files are named data_fl.0.dat, data_fl.50.dat, data_fl.100.dat, data_fl.150.dat, ..., data_fl.1500.dat i.e. the data has been written at intervals of 50 time steps.

Edit 2: I have plotted using pdfcairo also, though I couldn't share the output here as an image. The difference between pdf obtained from qt window and that from pdfcairo is that in the latter the arrows are not as sharp (they appear thicker) as in qt.

damaihati
  • 101
  • 2
  • 2
    What do you mean with "high resolution"? Do you want a pixel graphic (e.g. PNG 2000x2000 px) or a vector graphic (e.g. PDF)? With a vector graphics format you can zoom-in as much as you like. Depending of the data, PNG might be smaller in file size compared to PDF. What are the names of the 30 files in each of the 10 subdirectories? – theozh Jul 30 '23 at 18:24

3 Answers3

3

If you want a high resolution PNG, try e.g. something like this:

set term pngcairo size 2000,2000
set output "SO76799020.png"
set size square
plot sin(x)/x    # or whatever you want
set output

If you want to plot all files in a directory into different plots, check this:

How to plot all data files in the directory with gnuplot?

If you have more specific problem, please edit your question with a detailed description what you want and what you have tried.

theozh
  • 22,244
  • 5
  • 28
  • 72
1

I use:

set term push
set term postscript enh landscape "Arial" 10 color dl 0.75
set out "gnu.ps"
set size 1.1,1.1
set origin -.1,-.05
rep
set size 1,1
set origin 0,0
set term pop
set out

to create a postscript file, then convert to PDF using ps2pdf in cygwin (if you are on windows).

Then I can open the PDF and zoom in as much as I want and the image is sharp.

helper
  • 76
  • 5
  • Thank you. Is it possible to generate PDF files directly to save resources instead of going via ps? In addition, can you explain what is the reason behind changing size and moving the origin before and after plotting? – damaihati Jul 31 '23 at 07:37
  • 1
    The size and origin changes were to make the plot look good to me. I frankly have not tried to create PDF files directly. I just tried "set term pdfcairo" and it produced similar results. I have not investigated the options, but I think it could work very well for you. – helper Jul 31 '23 at 16:02
-1

I experimented and this works for me:

set term push # save current terminal that is used to view graph
set term pdfcairo enh font "Arial,15" color dl 0.75 size 9,6.5 # set terminal to pdfcairo with parameters I found to work
# Arial font, color plot, dash length (dl) 0.75 - from previous work, may not be needed
# size 9 inch by 6.5 inch - fit page well
set out "gnu.pdf" # set filename for output
set size 0.95,0.95 # size plot to fit well with axis labels
set origin 0.025,0.01 # position plot on page
rep # create plot (replot)
set size 1,1 # reset size to default
set origin 0,0 # reset plot position
set term pop # set term to previous (saved) terminal type
set out # clear output filename - return to original windowed plotting

I save this to a gnuplot file (*.plt or *,dem) and load it when i want a pdf version of my plot. For example, save it to pdf_plot.plt in <gnuplot directory>\share\ and type:

load 'pdf_plot.plt'

to make a pdf called gnu.pdf. If you want a more complete answer, See:

Gnuplot pdf output overwrite on Windows

helper
  • 76
  • 5
  • 3
    Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney Aug 06 '23 at 00:55