1

I use gnuplot command below to plot trajectories

plot -22.5 lw 3,22.5 lw 3, 'hydro_15/hydro_15.01/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'black','hydro_15/hydro_15.02/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'orange','hydro_15/hydro_15.03/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'violet','hydro_15/hydro_15.04/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'red','hydro_15/hydro_15.05/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'cyan','hydro_15/hydro_15.06/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'blue','hydro_15/hydro_15.07/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'green','hydro_15/hydro_15.08/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'magenta','hydro_15/hydro_15.09/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'brown','hydro_15/hydro_15.10/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'coral'

Can I make it shorter maybe by using for loop or something else. Sometime I have 40 files to plot which makes command very lengthy

1
  • Which terminal are you using? Do you want to a) plot all files into one plot? or b) plot the different files into an animation via terminal gif animate? or c) plot the files into different graph files, e.g. via terminal pngcairo and merge them to an animation with another software? Commented Apr 7, 2022 at 9:27

1 Answer 1

1

Since you are using different colors by name, I assume you want to plot all datafiles into one graph (no different frames or animations, etc.)

You could do something like this: (here just a loop of 9 files and colors, assuming your files have two digit numbers ranging from 01 to 09)

Script:

### plotting files in a loop into one graph
reset session

myFile(i) = sprintf('hydro_15/hydro_15.%02d/tracer_com.dat',i)

myColors = "black orange violet red cyan blue green magenta brown"
myColor(i) = word(myColors,i)

myCalc(col1,col2) = sqrt(column(col1)**2 + column(col2)**2)

plot -22.5 lw 3, \
      22.5 lw 3, \
      for [i=1:9] myFile(i) u (myCalc(2,3)):4 w l lc myColor(i)
### end of script
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.