Matplotlib: using non-linear scale on a polar plot

Viewed 364

I would like to draw a measured antenna radiation pattern. Currently I'm using the following script:

#!/usr/bin/env python3 -u
# vim: set ai et ts=4 sw=4:

from math import pi
import matplotlib.pyplot as plt
import csv

xs = []
ys = []
with open('raw-data.csv', newline = '') as f:
    for row in csv.reader(f, delimiter = ',', quotechar = '"'):
        xs += [ 2*pi*float(row[0])/360 ]
        ys += [ float(row[1]) ]

max_y = max(ys)
ys = [ y - max_y for y in ys ]

dpi = 80
fig = plt.figure(dpi = dpi, figsize = (512 / dpi, 384 / dpi) )

ax = plt.subplot(111, projection='polar')
ax.set_theta_offset(2*pi*90/360)
ax.plot(xs, ys, linestyle = 'solid', linewidth=3)
ax.set_rmax(0)
ax.set_rticks([-6*i for i in range(0,7)])
ax.set_yticklabels([''] + [str(-6*i) for i in range(1,7)])
ax.set_rlabel_position(0)
ax.set_thetagrids(range(0, 360, 15))
ax.set_theta_direction(-1)
ax.grid(True)

fig.savefig('linear.png')

And here is raw-data.csv:

0,-31.4
10,-31.9
20,-32
30,-32.4
40,-38.1
50,-41.1
60,-44.5
70,-59
80,-73
90,-67.3
100,-70.5
110,-62.1
120,-58.2
130,-55.7
140,-55.6
150,-54.7
160,-50.3
170,-43.7
180,-40.8
190,-41.2
200,-43.2
210,-45.9
220,-49.7
230,-53.8
240,-57.3
250,-60.6
260,-65.2
270,-61.6
280,-61.1
290,-60.8
300,-52.9
310,-46.2
320,-39.7
330,-35.1
340,-33.3
350,-31.9
360,-31.4

I'm almost happy with the result:

enter image description here

But I would like the scale to be a little different, like the one commonly used by ARRL. Here is an example:

enter image description here

Note that the scale is non-linear. Here is how The ARRL Antenna Book describes it:

The modified logarithmic grid used by the ARRL has a system of concentric grid lines spaced according to the loga- rithm of 0.89 times the value of the signal voltage. In this grid, minor lobes that are 30 and 40 dB down from the main lobe are distinguishable. Such lobes are of concern in VHF and UHF work. The spacing between plotted points at 0 dB and –3 dB is significantly greater than the spacing between –20 and –23 dB, which in turn is significantly greater than the spacing between –50 and –53 dB. For example, the scale distance covered by 0 to –3 dB is about 1/10 of the radius of the chart. The scale distance for the next 3-dB increment (to –6 dB) is slightly less, 89% of the first, to be exact. The scale distance for the next 3-dB increment (to –9 dB) is again 89% of the second. The scale is constructed so that the progression ends with –100 dB at chart center. The periodicity of spacing thus corresponds generally to the relative significance of such changes in antenna performance. Antenna pattern plots in this publication are made on the modified-log grid similar to that shown in Fig A-(C).

I don't need the exact method used by ARRL, but something that looks similar would be nice. I tried different approaches but didn't succeed. For instance, when I try to use ax.set_rscale('function',... I get images like this one:

enter image description here

A little piece of advice would be much appreciated.

0 Answers
Related