How do I limit a gnuplot polar to a 180 degree range? - gnuplot

I am attempting to use gnuplot to plot the off axis response of a loudspeaker in the range +/- 90 degrees. I have this working nicely, almost entirely as a result of Creating a microphone polar pattern plot in gnuplot
I would like to extend this so it presents the forward" 180 range only however I don't know how to do this & would appreciate some pointers.
This is my code so far
gnuplot <<EOF
set terminal pngcairo size ${WIDTH}/2,${HEIGHT}/2 font ',10'
set polar
set angle degrees
set size ratio 1
set tmargin 3
set bmargin 3
set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11
unset border
unset xtics
unset ytics
set xrange [-30:30]
set yrange [-30:30]
set key
r=1
set rrange [0:r]
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '180°' center at first 0, first -r*1.05
set label '-90°' right at first -r*1.05, 0
set label '+90°' left at first r*1.05, 0
set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis
set key outside top right
set style line 11 lw 2
set output '${PREFIX}_polar.png'
set multiplot layout 1,2 title "Circular Polar Response"
set title "Normalised"
plot '${PREFIX}_norm_polar_1000.txt' t '1k' w lp ls 11 lt 1 pt -1 , \
'${PREFIX}_norm_polar_2000.txt' t '2k' w lp ls 11 lt 2 pt -1 , \
'${PREFIX}_norm_polar_4000.txt' t '4k' w lp ls 11 lt 3 pt -1 , \
'${PREFIX}_norm_polar_8000.txt' t '8k' w lp ls 11 lt 4 pt -1 , \
'${PREFIX}_norm_polar_16000.txt' t '16k' w lp ls 11 lt 5 pt -1
set title "Unnormalised"
plot '${PREFIX}_polar_1000.txt' t '1k' w lp ls 11 lt 1 pt -1 , \
'${PREFIX}_polar_2000.txt' t '2k' w lp ls 11 lt 2 pt -1 , \
'${PREFIX}_polar_4000.txt' t '4k' w lp ls 11 lt 3 pt -1 , \
'${PREFIX}_polar_8000.txt' t '8k' w lp ls 11 lt 4 pt -1 , \
'${PREFIX}_polar_16000.txt' t '16k' w lp ls 11 lt 5 pt -1
EOF
the outcome is
the data looks like this (this is the 1k line in the example picture)
180 0.657067
172.5 0.6832
165 0.717767
157.5 0.7461
150 0.7747
142.5 0.806167
135 0.835633
127.5 0.865167
120 0.890533
112.5 0.918133
105 0.929633
97.5 0.9566
90 0.9632
82.5 0.9566
75 0.929633
67.5 0.918133
60 0.890533
52.5 0.865167
45 0.835633
37.5 0.806167
30 0.7747
22.5 0.7461
15 0.717767
7.5 0.6832
0 0.657067

Gnuplot gets confused if you use xrange and yrange setting which contradict the rrange setting. Thats probably why the yrange settings are ignored.
Then, you must also use set size ratio -1 in order to get the same scaling in x and yrange. When plotting only the upper two quadrants, you would get a wrong aspect ratio with set size square.
set terminal pngcairo font ',10'
set polar
set angle degrees
set size ratio 1
set lmargin 8
set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11
unset border
unset tics
set xrange [-1:1]
set yrange [0:1]
set size ratio -1
r = 1
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '-90°' right at first -r*1.05, 0
set label '+90°' left at first r*1.05, 0
set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis
set key outside top right
set output 'polar.png'
plot 'norm_polar_1000.txt' w lp ls 1 t '1k'

Related

Shifting of axis title and sub-title in Gnuplot histogram

Mr data file is
# test.dat
# Sample No. Phenol Red Neutral Red Bromophenol Blue Bromocresol Green Mixed Indicator
1 80 69 223 222 130
2 89 62 321 267 160
3 92 67 248 276 147
Gnuplot code is
#
#
###
reset session
###
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "test.eps"
#------------------------------------------------------------------------------
set style line 1 lt 4 lw 1 lc rgb "#4169E1"
set style line 2 lt 4 lw 1 lc rgb "#2E8B57"
set style line 3 lt 5 lw 1 lc rgb "#FF4500"
set style line 4 lt 4 lw 1 lc rgb "#FAD02C"
set style line 5 lt 4 lw 1 lc rgb "#FF0080"
#------------------------------------------------------------------------------
set xtics out scale 1.5
set ytics out scale 1.5
set ytics nomirror
set yrange [0:350]
set key off
set tics font ", 16"
set xlabel "Sample No. " font ",16"
set ylabel "Moisture Content ({/Symbol \155}g of H_{2}O/g of melt)" font ",16"
set key samplen 2 spacing 1.65 font ",14" width -1.0
set key inside left horizontal
set style fill solid border
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.4
# ----------------------------------------
set style data histogram
plot \
newhistogram "Direct titration", \
'test.dat' using 2:xtic(1) ls 4 axes x1y1 title "Phenol Red", \
'' u 3 ls 5 axes x1y1 title "Neutral Red", \
newhistogram "Back-titration", \
'test.dat.dat' using 4:xtic(1) ls 1 axes x1y1 title "Bromophenol Blue", \
'' u 5 ls 2 axes x1y1 title "Bromocresol Green", \
'' u 6 ls 3 axes x1y1 title "Mixed Indicator"
# ----------------------------------------
##
Script works fine. I would like to provide more spacing between the tick labels (1,2,3) and the sub-title (Direct titration and Back-titration) as well as spacing between the sub-titles and axis title. How can it be done?
set xlabel offset 0, -1 will shift both the subtitles and the axis title downward by one character height.
set xlabel "\nTEXT" will create a two-line axis label and place TEXT on the second line.
Modifying your xlabel command to be
set xlabel "\nSample No. " font ",16" offset 0,-1
will make both those changes.

Polar plot in gnuplot

I have a problem. Im trying to do a polar plot, the fact it's that i want to plot some theorical line as some experimental data in the plot. But the theorical line has a range different of the experimental data because i had to do it like that to had gnuplot paint it.
I have the following script:
####
reset
set encoding utf8
set size 1,1
set terminal epslatex
set output "direccionalidad.tex"
unset border
set polar
set angles degrees #set gnuplot on degrees instead of radians
set style line 10 lt 1 lc 0 lw 0.3
set grid polar 30 #set the grid to be displayed every 60 degrees
set grid ls 10
set trange[-90:90]
f(t)=27.934*sin(1.81651*t+96.1991) # Theorical line
set xrange[-31:32]
set yrange[-30:30]
set xtics axis #disply the xtics on the axis instead of on the border
set ytics axis
set xtics scale 0 #"remove" the tics so that only the y tics are displayedj
set ytics (0, 6, 12) #make the ytics go from the center (0) to 6000 with incrment of 1000
unset ytics
set xtics ("5" 6, "15" 16.5, "30" 32)
# set the xtics only go from 0 to 6000 with increment of1000 but do not display anything. This has to be done otherwise the grid will not be displayed correctly.
set rtics (5,15,30)
set rtics format ' ' scale 0
set_label(x, text) = sprintf("set label '%s' at (32*cos(%f)), (32*sin(%f)) center", text, x, x) #this places a label on the outside
eval set_label(0, "0")
eval set_label(30, "30")
eval set_label(60, "60")
eval set_label(90, "90")
eval set_label(120, "120")
eval set_label(150, "150")
eval set_label(180, "180")
eval set_label(-150, "-150")
eval set_label(-120, "-120")
eval set_label(-90, "-90")
eval set_label(-60, "-60")
eval set_label(-30, "-30")
set size square
#PLOTS
plot "direccionalidaddatos.txt" u 1:3 pointtype 7 ps 2 lt 1 lw 3 lc rgb 'blue' notitle ,\
f(t) dt '-' lc rgb 'blue' notitle
#ACABAMOS
###
And here there are some examples of columns in the direccionalidaddatos.txt archive, the column in the middle it's just the angle in radians but it's usless cause i just want the angle in degrees so just ignore it ;):
-90 -1.570796327 0.1
-85 -1.483529864 0.2
-80 -1.396263402 0.4
-75 -1.308996939 0.7
-70 -1.221730476 1.1
-65 -1.134464014 1.7
-60 -1.047197551 2.5
#
And the result it is the image Polar plot
As you see in the image there are two branches that have no points, i want those branches to simply don't disappear cause they don't mean notihng in the graphic.So if anyone knows a form to made dissapear the branches, or to improve the script let me know hehe.
Thanks so much.
Can you just reduce the sampled range for the second plot component?
plot "direccionalidaddatos.txt" u 1:3 pointtype 7 ps 2 lt 1 lw 3 lc rgb 'blue' notitle ,\
[-52:45] '+' using 1:(f($1)) with lines dt '-' lc rgb 'blue' notitle

How do I edit the time values on the x-axis to start from zero when using gnuplot?

I do not want to change my data files that come with the first column containing the time values. Then I formatted it on gnuplot to show only the hour and minute. But it is a bit ugly to start the time from 8:00. I would like to start it from 0 and keep the values at the same pace of the data file. I was trying to use a constant like this example shows How do I make a plot in gnuplot with the lowest value automatically subtracted from the y data? but it is not working.
Here are my source and the plot.
#!/usr/bin/gnuplot
# set grid
set key outside bottom center horizontal
set key font ",19"
set style line 1 lc rgb '#E02F44' lt 1 lw 1 ps 0.5 pt 7 # input throughput
set style line 2 lc rgb '#FF780A' lt 1 lw 1 ps 0.5 pt 1 # output throughput
set style line 3 lc rgb '#56A64B' lt 1 lw 1 ps 0.5 pt 2 # average processing latency
set style line 4 lc rgb '#000000' lt 1 lw 1 ps 0.5 pt 3 # 99th percentile processing latency
set style arrow 1 heads ls 4
set style arrow 2 head ls 4
set terminal pdf
set pointintervalbox 0
set datafile separator ','
set output "Cost-20K-ThroughputVsLatency.pdf"
#set title ""
set xlabel "time (minutes)" font ",17" offset 0,1,0
set xtics font ",8" offset 0,0.5,0
set xdata time # tells gnuplot the x axis is time data
set timefmt "%Y-%m-%d %H:%M:%S" # specify our time string format
set format x "%H:%M" # otherwise it will show only MM:SS
set xrange ["2020-05-07 08:05:00":"2020-05-07 09:50:00"]
set ylabel "Throughput (K rec/sec)" font ",18" offset 0,0,0
set yrange [0:7]
set ytics font ",20"
#set y2label "processing latency (seconds)" font ",18" offset -1.5,0,0
set y2range [0:25]
set ytics nomirror
set y2tics 0, 5 font ",17"
plot "throughput-vs-latency-20K.csv" using 1:(column(2)/1000) title "IN throughput" with linespoints ls 1 axis x1y1 \
, "throughput-vs-latency-20K.csv" using 1:(column(10)/1000) title "OUT throughput" with linespoints ls 2 axis x1y1 \
, "throughput-vs-latency-20K.csv" using 1:(column(18)/1000) title "avg. latency" with linespoints ls 3 axis x1y2 \
, "throughput-vs-latency-20K.csv" using 1:(column(26)/1000) title "99th latency" with linespoints ls 4 axis x1y2
UPDATE
I changed my script like you said #theozh but I am still not getting the x axis starting from 0.
set key bottom right
set key font ",11"
set style line 1 lc rgb '#E02F44' lt 1 lw 1 ps 0.5 pt 7 # input throughput
set style line 2 lc rgb '#FF780A' lt 1 lw 1 ps 0.5 pt 1 # output throughput
set style line 3 lc rgb '#56A64B' lt 1 lw 1 ps 0.5 pt 2 # average processing latency
set style line 4 lc rgb '#000000' lt 1 lw 1 ps 0.5 pt 3 # 99th percentile processing latency
set style arrow 1 heads ls 4
set term pdfcairo size 5.0in,2.5in
set pointintervalbox 0
set datafile separator ','
set tmargin 1.5
set border 1+2+8
set xtics nomirror
set output "throughput-latency-increasingK-TaxiRideNYC-50Kpersec.pdf"
myTimeFmt = "%Y-%m-%d %H:%M:%S"
set xlabel "time (minutes)" font ",9" offset 0,1.5,0
set xtics font ",8" #rotate by 45 right
set ylabel "Throughput (K rec/sec)" font ",10" offset 2,0,0
set yrange [0:3.5]
set y2label "processing latency (seconds)" font ",10" offset -2,0,0
set y2range [0:14]
set ytics nomirror
set y2tics 0, 2
set xdata time # tells gnuplot the x axis is time data
set format x "%M" time
plot t=0 "throughput-latency-increasing.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)/1000) title "IN throughput" with linespoints ls 1 axis x1y1 \
, t=0 "throughput-latency-increasing.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(18)/1000) title "avg. latency" with linespoints ls 3 axis x1y2 \
, 4/0 t "# of tuples pre-aggregating" with vectors arrowstyle 1
values are here:
"Time","pre_aggregate-outPool[0]-avg","pre_aggregate-outPool[1]-avg","pre_aggregate-outPool[2]-avg","pre_aggregate-outPool[3]-avg","pre_aggregate-outPool[4]-avg","pre_aggregate-outPool[5]-avg","pre_aggregate-outPool[6]-avg","pre_aggregate-outPool[7]-avg","pre_aggregate-outPool[0]-99","pre_aggregate-outPool[1]-99","pre_aggregate-outPool[2]-99","pre_aggregate-outPool[3]-99","pre_aggregate-outPool[4]-99","pre_aggregate-outPool[5]-99","pre_aggregate-outPool[6]-99","pre_aggregate-outPool[7]-99","pre_aggregate[0]-param","pre_aggregate[1]-param","pre_aggregate[2]-param","pre_aggregate[3]-param","pre_aggregate[4]-param","pre_aggregate[5]-param","pre_aggregate[6]-param","pre_aggregate[7]-param"
"2020-04-27 10:22:45",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,70,75,79,33,41,62,75,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:00",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,75,79,33,33,33,37,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:15",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,33,33,33,33,33,33,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:30",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,62,66,50,62,66,45,50,66,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:45",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,62,66,50,62,66,45,50,66,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:24:00",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,33,33,33,33,33,33,50000,50000,50000,50000,50000,50000,50000,50000
The following example uses the newer gnuplot date time syntax (see help timecolumn), e.g. timecolumn(1,myTimeFmt) and set format x "%H:%M" time.
In order to normalize your time series to the first data point you have to store this time into a variable, e.g. t0 which you can "re-use" in successive plot commands from the same datafile.
Note the different time format for the x axis: "%H:%M" for day time and "%tH:%tM" for hours exceeding 24 hours or minutes exceeding 60 minutes, see help time_specifiers.
Edit:
for better readability of the plot command, I "outsourced" the normalization into a function Normalize(). But note that t=0 is still required at the beginning of the plot command.
in case you have some (uncommented) header lines, you need to skip them via skip <number of header lines>.
Code:
### normalize time data relative to start time
reset session
myTimeFmt = "%Y-%m-%d %H:%M:%S"
# create some test data
set table $Data
plot '+' u (strftime(myTimeFmt,time(0) + $1*3600*2)):(cos($1)) w table
unset table
# function to normalize time column to first value
Normalize(c) = (t==0?(t0=timecolumn(c,myTimeFmt),t=1):NaN, timecolumn(c,myTimeFmt)-t0)
# in case there are uncommented header lines skip them
SkipHeaderLines = 0
set multiplot layout 2,1
set format x "%Y\n%m-%d\n%H:%M" time
plot $Data u (timecolumn(1,myTimeFmt)):3 skip SkipHeaderLines w l ti "absolute time"
set format x "%tH:%tM" time
plot t=0 $Data u (Normalize(1)):3 skip SkipHeaderLines w l ti "relative time"
unset multiplot
### end of code
Result:

Why my commands do not work for gnuplot?

I have input file test.dat that contains
1 1
2 2
3 3
4 4
I wrote the script for gnuplot:
gnuplot <<EOF
set term png size 1000,1000;
set output "out.png";
set arrow from graph 0,1 to graph 0,1.1 filled
set arrow from graph 1,0 to graph 1.1,0 filled
set tmargin 5
set rmargin 20
set border 3
set tics nomirror
set grid
set xtics font "Verdana,14"
set ytics font "Verdana,14"
set nokey
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "black"
set ylabel "Efficiency, %" offset 2,0,0 font "Verdana,14"
set xlabel "Cores, N" offset 0,0,0 font "Verdana,14"
func1(x) = x / 2
func2(x) = x * 2
plot "test.dat" u (func1($1)):(func2($2)) ls 1 smooth csplines;
EOF
But the error occurs when you try to start it:
gnuplot> plot "test.dat" u (func1()):(func2()) ls 1 smooth csplines;
line 0: invalid expression
The dollar signs are interpreted as starting a shell variable. Use column instead:
gnuplot <<EOF
set term png size 1000,1000;
set output "out.png";
func1(x) = x / 2
func2(x) = x * 2
plot "test.dat" u (func1(column(1))):(func2(column(2))) ls 1 smooth csplines;
EOF

Gnuplot set background color of data label

I want to set the background of data labels to white! The considered plot is a data plot of the following data (gnuDC.dat):
4 1570.96 1571
8 770.63 771
12 530.33 530
16 385.13 385
24 261.87 262
48 137.71 138
96 81.42 81
The plot command reads:
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
Which gives me:
It looks ok but think one could read the lables better when the would have an white background. Is there an easy way to add the white background for all labels at once?
Here is the whole print file:
set terminal postscript eps size 14cm,10cm enhanced color \
font 'Helvetica,18' linewidth 2
set output 'test.eps'
# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 lt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set xtics nomirror
set ytics nomirror
set style line 100 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
set style line 200 lc rgb '#a2142f' lt 1 lw 2 pt 7 ps 1.5
set pointintervalbox 0
set style line 1 lc rgb '#0072bd' lt 1 lw 1 pt 9 pi -10 ps 2
set style line 2 lc rgb '#77ac30' lt 1 lw 1 pt 7 pi -10 ps 2
set style line 3 lc rgb '#d95319' lt 1 lw 1 pt 1 pi -10 ps 2
set bmargin 4
set lmargin 5
set rmargin 4
unset title
set size 1,1
#set origin 0,0.27
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
With gnuplot version 5 there is a boxed option which does exactly this: give labels a background and, if you want, also a border. The style is controlled with set style textbox, e.g.
set style textbox opaque noborder
plot ... with labels boxed ...
Applied to your script (with some minor changes due to the changed dash handling since 5.0):
# Line style for axes
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 dt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set tics nomirror
set linetype 1 lc rgb '#0072bd' pt 9 pi -10 ps 2 dt 3
set bmargin 4
set lmargin 5
set rmargin 4
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
set style textbox opaque noborder
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p lt 1, \
"gnuDC.dat" using 1:2:3 with labels boxed center offset 2.,0.7 font "Helvetica,10" tc ls 1 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines lt 1
No, for versions 4.6 and earlier there isn't an easy way to achieve this.

Resources