问题
I have a gnuplot datafile that looks like this:
1 4810 582 573 587
2 99k 67k 56k 40k
3 119k 82k 68k 49k
4 119k 81k 68k 49k
5 120k 81k 65k 45k
6 121k 82k 65k 44k
7 124k 106k 97k 86k
8 128k 134k 131k 131k
9 128k 130k 131k 135k
10 129k 133k 130k 132k
First column will be on the X-axis labeled as "Time", the rest are the different interrupt values with respect to time (i.e. IRQ1, IRQ2, IRQ3, IRQ4)
The problem when generating a plot with this is that gnuplot does not seem to interpret the abbreviated values with the K suffix as numbers in the thousands, but instead as raw values such as 99, 67, 119, etc. Thus the lines will jump from around 5000 at time 1 and drop to around 100 in the graph.
Are there any options to tell gnuplot to automatically interpret abbreviated values and plot them accordingly?
回答1:
I think there is no direct way of telling gnuplot of how to interpret the input in this case.
You can, however, write your own function that converts the string-input to numbers
check(x)=(pos=strstrt(x,"k"),\
pos > 0 ? real(substr(x,1,pos-1))*1000 : real(x))
The function check first determines the position of the letter 'k' in the input. (The function strstrt returns '0' if the input x does not contain the letter 'k'.)
If the input contains the letter 'k', take the input, discard the last letter, convert the remaining part to a number and multiply it by 1000.
If the input does not contain 'k', return the input
Now you can plot the data file (assuming its name is test):
plot 'test' u 1:(check(stringcolumn(2))) w l
This should do the job!
回答2:
a non-purely gnuplot, unix solution would use process substitution:
plot "<(sed 's/k/000/g' datafile.dat)" u 1:2 w lp
The sed 's/k/000/g' command replaces all occurrences of the character k with 000 in datafile.dat: e.g. 96k will be replaced with 96000.
The output is similar to the plot posted by @Knorr
来源:https://stackoverflow.com/questions/33507660/plotting-datafile-with-abbreviated-values-with-gnuplot