Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Y Label in groups with Gnuplot

I have this points:

0.00049 1.509
0.00098 1.510
0.00195 1.511
0.00293 1.509
0.00391 1.510
0.00586 1.523
0.00781 1.512
0.01172 1.514
0.01562 1.510
0.02344 1.511
0.03125 1.510
0.04688 7.053
0.06250 7.054
0.09375 7.187
0.125 7.184
0.1875 7.177
0.25 7.207
0.375 16.588
0.5 24.930
0.75 39.394
1 56.615
1.5 77.308
2 84.909
3 89.056
4 88.485
6 88.678
8 89.022
12 88.513
16 88.369
24 88.512
32 88.536
48 87.792
64 87.716
96 87.589
128 87.608
192 87.457
256 87.388

And this gnuplot script:

#! /usr/bin/gnuplot

set terminal png
set output "lat_mem_rd.png"
set title "Memory Latency Benchmark (Stride 512)"

set xlabel "Memory Depth (MB)"
set ylabel "Latency (ns)"
set xtics rotate by 45 offset 0,-1
set xtics font "Times-Roman, 8"

set grid

set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1   # --- blue

plot "lat_mem_rd.dat" using (log($1)):2:xtic(1) smooth unique title "" with linespoints ls 1

which generates this graphic:

Graphic Generated

But i want to show the y values in the y label with one of the approximated values in those approximations, for example, for all of the values with x values between 3 and 256, the y label is set to just one, maybe 88.513 that corresponds to x=12 or other (or maybe the average of those points if its not very difficult)...

The same for x values between 0 and 0.02344 and for x values between 0.03125 and 0.1875.

This y values will substitute the values 10, 20, ..., 90.

like image 284
José Ricardo Ribeiro Avatar asked Dec 01 '22 20:12

José Ricardo Ribeiro


1 Answers

Here is a modification of your script that might do what you want, if I understand you correctly:

set title "Memory Latency Benchmark (Stride 512)"

set xlabel "Memory Depth (MB)"
set ylabel "Latency (ns)"
set xtics rotate by 45 offset 0,-1
set xtics font "Times-Roman, 8"

set grid

a = ""; p = 0; nn = 1; nt = 37; d = 4; s = 0

f(x) = (x>p+d || nn >= nt)?(nn=nn+1, p=x, a=a." ".sprintf("%5.2f", s/n), n=1, s=x):(nn=nn+1, p=x, s=s+x, n=n+1)

plot "lat_mem_rd.dat" using 1:(f($2)) # Just to set array "a"

set ytics 0,0,0

set yrange [0:90]

set for [aa in a] ytics add (aa aa)

set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1   # --- blue

set terminal png
set output "lat_mem_rd.png" 

plot "lat_mem_rd.dat" using (log($1)):2:xtic(1) smooth unique title "" with linespoints ls 1

This script produces this plot:

enter image description here

The strategy is to accumulate a sum of Y-values and calculate an average every time the Y-value increases by at least an amount d; these averages are stored in a string variable "a", which is looped over to set the ytic values before the final plot command. This way clusters of closely-spaced Y-values give rise to a ytic at their average value; I think that was what you wanted.

like image 157
Lee Phillips Avatar answered Dec 04 '22 04:12

Lee Phillips