1

I've crawled around the net, but could not find a sufficient solution for my issue. I have some csv-stuffed data of my cpu usage over time (per day split)

Time CPU used%
1    1   35
2    1   28
3    1   20
4    1   45
5    1   15

for each CPU that I have in my laptop. And on top of that I have some statistical calculated results of my usage from the last day like

CPU Max% Avg%
1   98  17
2   99  23
3   95  10
etc.

Using gnuplot I'm able to draw a line plot of my time series data and getting nice results. However I also want to add the statistics as a table beneath my line plot.

But I could not find a way to plot my raw data as a table using gnuplot. Does someone know a way? It doesn't have to be gnuplot, I just want to automate my plot-generation using shell commands, so gnuplot was very convenient for this.

Does someone have any idea?

5
  • You could add some of this as labels, but I would recommend using a proper document setting tool, e.g. HTML, Latex, etc. Commented Feb 20, 2018 at 17:12
  • Hi @Thor, do you have an example for Latex? I also though about this way in combination with gnuplot, but I wasn't sure how it works. Commented Feb 20, 2018 at 17:26
  • perhaps something like this - tex.stackexchange.com/a/146719 Commented Feb 20, 2018 at 18:19
  • This looks like a good example as well. Note that this answer uses tikz for plotting the data, this may be a good idea as you are able to homogenize fonts etc. Commented Feb 20, 2018 at 19:01
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask. Commented Feb 20, 2018 at 21:41

1 Answer 1

1

Although this unanswered question is more than 3 years old, it still might be of interest to the OP or someone else. It is not completely clear how your complete data looks like, i.e. whether is stored in a single file or in separate files. So, I assumed something which is convenient to handle. It certainly can be adapted to other formats.

  • The data will have a timestamp, the number of the CPU and the CPU usage value.
  • Column separator is tab.
  • The different CPUs are separated by two empty lines, with this you can address the different blocks via index.
  • gnuplot can do the statistics via stats.
  • For printing the statistics into the plot (as "table"), simply use labels (check help label).
  • The example below is creating some random dummy data.
  • The minimum CPU usage could also be easily added.

Data: (example one file, actually here: one datablock)

# date time             CPU     usage
2021-08-01 00:00:00     1       14.9574
2021-08-01 00:05:00     1       16.1165
2021-08-01 00:10:00     1       17.6627
2021-08-01 00:15:00     1       14.8799
...


2021-08-01 00:00:00     2       18.8313
2021-08-01 00:05:00     2       17.6595
2021-08-01 00:10:00     2       19.1912
2021-08-01 00:15:00     2       18.731
...


...
2021-08-01 00:00:00     8       39.9016
2021-08-01 00:05:00     8       37.8723
2021-08-01 00:10:00     8       40.2769
2021-08-01 00:15:00     8       38.9694

Code:

### plot time series and statistics label
reset session

myTimeFmt = "%Y-%m-%d %H:%M:%S"
t0 = strptime(myTimeFmt,"2021-08-01")
Ncpu = 8

# create some random test data
set print $Data
    p(t) = (_tmp=p0+rand(0)*6-3, _tmp>100 ? 100 : _tmp<0 ? 0 : _tmp)
    do for [cpu=1:Ncpu] {
        p0 = rand(0)*100
        do for [t=t0:t0+24*3600:5*60] {       # steps in 5 minutes for 1 day
            print sprintf("%s\t%d\t%g",strftime(myTimeFmt,t),cpu,p0=p(0))
        }
        print ""; print ""   # two empty lines
    }
set print

set datafile separator tab
set format x "%H:%M" time
set key out
set grid x,y
set xlabel sprintf("%s",strftime("Date: %Y-%m-%d",t0))
set ylabel "CPU usage / %" font ",12"

# create statistics:
set print $Statistics
    do for [i=1:Ncpu] {
        stats $Data u 3 index i-1 nooutput
        print sprintf("%d %.1f %.1f",i,STATS_max,STATS_mean)
    }
set print

set bmargin screen 0.25
myLabelPosY = 0.11

set label 1 at screen 0.02, screen myLabelPosY "\nMax:\nAvg:"
do for [i=1:Ncpu] {
    set label i+1 at screen 1./(Ncpu+1)*i, myLabelPosY \
       sprintf("CPU %d:\n%s%%\n%s%%",i,word($Statistics[i],2),word($Statistics[i],3)) 
}

plot for [i=1:Ncpu] $Data u (timecolumn(1,myTimeFmt)):3 index i-1 w l ti sprintf("CPU %d",i)
### end of code

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

I'm just seeing your awesome responses all over. I may have to just go to your profile and look for every question you responded to learn so much. I am disappointed that many of these answers have not been well appreciated.
@MathX thank you for your comment. Never mind, that's life. I am thrilled by finding solutions to interesting gnuplot questions with the given gnuplot options. And it is also a memory aid for myself. It happened that I had to look up old answers, because I forgot how to do it.
Also what Terminal do you usually use? your plots look very nice.
@MathX for most answers here, I am using the interactive terminal wxt under Windows and export the graph to PNG. The graphs created by terminal pngcairo usually look slightly different.
@MathX if you have an issue with png output which is not covered or solved by previous questions, don't hesitate to open a new question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.