gnuplot bashshell to plot several curves in one window

纵饮孤独 提交于 2020-01-14 04:09:46

问题


I need to plot a couple of curves in a single window. Using for loop in bash shell I've been able to plot them on separate files , but no success in sketching them on a single pic. I would appreciate it if you can guide me on how to resolve this issue.

I tried to implement the example in thie link for loop inside gnuplot? but it gives me an error saying: ':' expected .I have gnuplot 4.2 installed. Thanks,

#!/bin/bash

for Counter in {1..9}; do
FILE="dataFile"$Counter".data"
    gnuplot <<EOF
    set xlabel "k"
    set ylabel "p(k)"
    set term png
    set output "${FILE}.png"
plot [1:50] '${FILE}'
EOF
done

回答1:


Looping inside the plot command works only since version 4.4 and would look like

file(n) = sprintf("dataFile%d.data", n)
plot for [i=1:9] file(i)

Using bash I would construct the plot command inside the bash loop and use this later in the gnuplot script:

for Counter in {1..9}; do
  FILE="dataFile${Counter}.data"
  if [ $Counter = 1 ]; then
    plot="plot '$FILE'"
  else
    plot=$plot", '$FILE'"
  fi
done
gnuplot <<EOF
set xlabel "k"
set ylabel "p(k)"
set term png
set output "output.png"
$plot
EOF


来源:https://stackoverflow.com/questions/26168854/gnuplot-bashshell-to-plot-several-curves-in-one-window

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