aplonis has asked for the wisdom of the Perl Monks concerning the following question:

Trying to generate an SVG for an azimuthal antenna plot from a single column of values in decibels, range -40 up to a fixed maximum of 10. I've got it working, sort of. But the concentric rings for -40, -30 ... +10 are all of evenly spaced diameters. So it doesn't look right compared to the usual way. Normally the outer donut for 0 to +10 is bigger than the next one down for -10 to 0. And so on, each ring getting thinner and thinner as it proceeds down to the innermost circle with a center point of -40 dB.

So this is likely more a math question, except that I'm trying to work it in Perl. Obviously, Perl/Tk does it somehow, since a log scale exists. Has anyone a link to such an example?

Here is a link to what I'm working on. Folder on KY8D.net

foo.n2p.txt is the data. Drop the .txt after download.
foo.svg is the SVG graphic created by Perl.
Nec2Go_Plot.png is the plot I'm trying to prettify.
N2P_to_SVG.txt is the Perl script.

What it's about: There's an older antenna analysis program called Nec2Go. I'm wanting to make its plots suitable for inclusion in magazine articles, etc. So its 1-pixel lines on plots with grey backgrounds just won't do. Otherwise, though, it's better than certain newer ones.

Replies are listed 'Best First'.
Re: Logarithmic Scale
by kikuchiyo (Hermit) on Jul 13, 2020 at 12:24 UTC

    You could do it with gnuplot: it can do polar plots with logarithmic axes, or even axes with arbitrary scaling functions in newer versions. You'd also have complete control over the presentation (line widths, colors etc.) and the output format.

    That said, I can't make sense of your data file: what data is in the columns, and where are the angles? Also, I can't download your perl script, it shows a server error instead.

      Thank you, I had considered gnuplot, but was sort of wanting to do it myself. I'd like something self-contained that I can call directly from LabVIEW. I'll burn an *.exe via pp once it's all tidy. The LabVIEW, along with any Perl will be distributed for free, source code and all, just as always I do.

      As for the *.n2p file, the first line is header. After then, because it's for an antenna modeled in "Free Space" (versus over ground), the tally of rows is 722. Those comprise two sets of 361. Each set of 361 represents a closed circle. The top closed circle is Azimuth, the lower one Elevation. Thus two cross-sections of the antenna's radiation lobe. And with each row of each set representing 1 degree of the circle, either azimuth or elevation. That for the two sets of rows.

      My Perl code, as presently constituted, deals only with the leftmost column, and just its first 361 rows.

      Describing all:

      Column 0 on left is net gain versus an isotropic radiator, comprising the sum of the other two columns.
      Column 1 in the middle is gain in the vertical plane (low because this is a horizontal antenna).
      Column 2 on the right is gain in the horizontal gain.

      Thus, data for two plots of antenna directionality at one given frequency. Not really high gain, because this is a very, very broadband antenna: a log-periodic sawtooth array.

      That *.n2p file, therefor, is the source data for both azimuthal plots: my SVG, and Net2Go's own screenshot. Only have the azimuthal working, so far. Have paused in hopes of properly spacing the concentric rings by some factor closer to logarithmic than linear.

        Thanks, that makes the layout of the data clear.

        Now that I've thought about it, I've never seen a polar plot distorted in a way you describe. The polar axis is in decibels, so it already uses logarithmic scale - by "making the outer donuts larger", as you say, you actually want to undo the logarithmic scaling, at least partially. In any case, I see this as a cosmetic alteration that may be harmful, because it changes the shape of the curve you want to show, without good reason.

        With that in mind, here is a gnuplot script that produces a graph close to what you want:

        set polar set rr [-40:10] set rtics 10 unset border unset xtics unset ytics set grid lt 1 lc rgb "blue" f(x) = (x+50)**2 g(x) = sqrt(x)-50 set nonlinear r via f(r) inverse g(r) plot '/tmp/foo.n2p' u ($0>0&&$0<=361 ? $0*pi/180. : 1/0):1 w l lw 2 n +otit

        The scaling function (that determines the spacing of the grid circles) is a square function (f(x) in the script) as opposed to exponential. You could use this function in your script if you prefer to stay with your pure perl solution.

      Humble apology for the *.pl causing a server error. I have changed the suffix from *.pl to *.txt, so now the server won't try to run it instead.

      I have no business getting in the middle of this discussion (thank you), but PDL might provide some useful visualization options, including an interface to gnuplot, PDL::Graphics::Gnuplot.
        A specific PDL thing that might save some lines of code would be to use PDL::Transform, possibly t_lookup.
Re: Logarithmic Scale
by Fletch (Bishop) on Jul 13, 2020 at 13:32 UTC

    Not a perl solution, but you might look at Vega-Lite and Voyager. Granted those are more intended for interactive use but I believe there's ways to get them to save either the SVG from the canvas it uses or (possibly) exporting to PNG.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Thank you, I will look at those. But I'm really wanting to do it myself. Ultimately, I will call it from LabVIEW. And LabVIEW has a log plot of its own, but not very pretty. Perhaps I'm too fussy.

      PS, it really was too bad about the cake. I was disappointed myself.