Search code examples
gnuplotpolar-coordinates

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


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

polar

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

Solution

  • 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'
    

    enter image description here