Home Ask Login Register

Developers Planet

Your answer is one click away!

Meir Zeilig-Hess February 2016

how to show time steps on the title of successive plots in gnuplot

I am using Gnuplot version 4.6. I am plotting graphs of a physical quantity (let's say, air pressure) as a function of space position, based on successively created datafiles. In order to obtain an animation of these graphs for different time steps, I am using the following loop:

gnuplot> do for [n=0:400]{plot [0:1] [0:1] sprintf("data.%04d.tab", n) using 1:5 with lines title 'Time in seconds= ' .n}

What I need is to show on these successive graphs the physical time that passed since the beginning of the simulation, and this time is just equal to the number of datafiles created up to that graph, times a constant time (the unit time of the physical problem, times the period between datafile writing

My question is - how can I show the physical time in the title, using the file numbers?

I tried to multiply the file number, n, by the constant time (in my problem: 9e^-6 seconds) but this restricts the number of plots. How can I overcome this?


bibi February 2016

use sprintf to manipulate strings.

In your case the title would be sprintf('Time in seconds= %.2f',n*9e-6)

So your command:

do for [n=0:400]{plot [0:1] [0:1] sprintf("data.%04d.tab", n) using 1:5 with lines title sprintf('Time in seconds= %.2f',n*9e-6)}

If you want the title (not the legend), you can use the set title command:

do for [n=0:400] { 
    set title  sprintf('Time in seconds= %.2f',n*9e-6)
    plot [0:1] [0:1] sprintf("data.%04d.tab", n) using 1:5 with lines nottile

A lot more can be done with strings, look HERE

Post Status

Asked in February 2016
Viewed 3,815 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life