This is a bit of an odd query, and probably demonstrates my ignorance of bash more than being a simple request for help. Then again, someone may have the perfect answer -- which would save me a lot of head-scratching.
I wanted to create a simple gnuplot command to produce a plot, repeatedly for different data. Whilst at the moment I will probably have to save the data into a temporary file in /dev/shm, I don't really want to. It feels like unnecessary complexity, when what I would instinctively do is pass the data through a pipe. However, just when I thought I had it sussed (thanks to theozh) , experiments prove me wrong.
I start with the file stack.gp, as follows:
### bar chart with conditional color
data = '/dev/stdin'
lhb = ARG1
myColor(col) = (_s=strcol(col), _s eq lhb ? 0xff3333 : 0x3333ff)
set style fill solid 0.5
set key noautotitle
stats data using 0:2 nooutput
set label 1 at STATS_max_x, STATS_mean_y sprintf("mean=%.1f",STATS_mean_y) offset 0,0.7 right
plot data using 0:2:(myColor(1)):xtic(1) w boxes lc rgb var, \
STATS_mean_y w l lw 2 lc "web-green"
As far as I understand things, the important thing here is:
- The first line, where the incoming data is stored; and
- The fact that this data is processed more than once (since I can easily do what I want, so long as I DON'T have the stats command).
The data is a very simple, two-column table:
A 8
B 6
C 4
D 3
and I can generate my output with the command:
< test.dat gnuplot --persist -c stack.gp 'C'
Perfect! Except it isn't, because this uses a temporary file (test.dat). What I actually intend to do is pipe the data in, similar to this approach:
cat otherfile.txt | awk ... | gnuplot -c stack.gp 'C'
This doesn't work with the original script (no valid data points), but it DOES work if I remove my stats command so that the data is only processed once. So lets try a few other approaches:
- data = '<cat'
- data = '-'
(1) again works for a single pass, but otherwise gives "x range is invalid" (2) Either gives "x range is invalid" or "No valid data points found in file" depending on 1- or 2-pass processing. Arghhh!
So, is there another approach? Once could be the reason why I started using gnuplot in the first place, which is the perl helper script feedgnuplot. However, so far I haven't managed to get this working either.
The post https://unix.stackexchange.com/questions/671446 goes into a little more detail. Similar discussions: how to make several plots from the same standard input data in gnuplot?
Being stubborn, logic suggests that this is possible, because I can create random test data (using set table $Data) and then analyse that. If I can do that, then surely I can populate $Data with the contents of piped data? I'm obviously not populating this correctly when using stdin...
Is there a solution? Or is this just not possible with the current version of gnuplot?