Gnuplot script, for loop within or adding to existing plot

瘦欲@ 提交于 2019-12-18 09:21:16

问题


I would like to plot a series of vertical lines in gnuplot at a set interval.

Some information about the plot.

The plot is mainly some data from a .dat file. The gnuplot script is called by a bash scripts which alters the gnu plot script using sed. This is a snipit of the an old bash script (ugly I'm sure).

sed -i 's/C = CONCEHOLD/C = '${$CO}'/g' $GNUPLOTROOT/plotviscosity.plt
gnuplot $GNUPLOTROOT/plotviscosity.plt
mv my-plot.ps $VISCPLOTNAME
sed -i 's/C = '${$CO}'/C = CONCEHOLD/g' $GNUPLOTROOT/plotviscosity.plt

with the . plt file looking like this.

set title "Viscosity vs Time, C = CONCEHOLD, beta = RATHOLD, zeta = ZETAHOLD"
set xlabel "Time"
set ylabel "Viscosity"
plot "viscout.dat" using 3:2 title 'Viscosity'
# Saving to my-plot.ps
load save.plt
#

I would like to add to this plot a series of vertical lines at a set repeating interval. I have found how to plot vertical lines via http://t16web.lanl.gov/Kawano/gnuplot/parametric-e.html

set parametric
const=3
set trange [1:4]
set xrange [0:5]
set yrange [0:5]
plot const,t

I would like to have

const=repititionperiod*i

where i is an integer belonging to (1,calculateduppedlimit].

I could input repititionperiod via sed again and in a similar vain calculateduppedlimit but need some sort of for loop either within gnuplot or a separate gnuplot script that adds a vertical line to the already created plot within a for loop in my bash script.

I can't find any information on loops within gnu plot or adding to a previously created plot.

Any advice gratefully received.


回答1:


EDIT: Gnuplot does now in fact now support a for loop, you can read about it here

As I understand gnuplot doesn't have a for loop, although you can generate one of sorts as follows:

Make a file "loop.gp" containing

const  = const + 1
#... some gnuplot commands ... 
if(const<100) reread

then in a gnuplot terminal, or script write,

const = 3; load "loop.gp";

This will give you a simple loop.

(this example is taken from the misc. section of http://t16web.lanl.gov/Kawano/gnuplot/index-e.html)

For your particular answer you might try adding arrows rather than paremetric lines, eg.

set arrow from const,1 to const,4 nohead

will do much the same thing.

In this case you loop.gp could be

const  = const + repititionperiod
#... some gnuplot commands ...  
set arrow from const,1 to const,4 nohead
if(const<calculatedupperlimit) reread

and you would run you loop with

const = 1; repititionperiod=2;calculatedupperlimit = 10; load "loop.gp"; replot;

The replot plots the arrows.

If you "just" want the lines and nothing else - then you will need to feed a graph to actually plot (a set of arrows doesn't count). The example you gave could then be used to plot the first vertical line.

hope this helps.

Tom



来源:https://stackoverflow.com/questions/4062999/gnuplot-script-for-loop-within-or-adding-to-existing-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!