2

I am trying to use logarithmic Y Axis in pgfplots polar charts by specifying ymode=log:

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymode=log, ymin=0, ymax=70,
        ytick=\empty, axis y line=none, 
        xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
        nodes near coords style={font=\footnotesize},
        nodes near coords=\pgfmathprintnumber{\pgfplotspointmeta}\%,
        visualization depends on={x\as\myx},
        nodes near coords style={anchor=\myx-180},
    ]
    \addplot+ [polar comb, green, line width=3pt, mark=none, ->]
    coordinates {(0,21.6) (180,15.8)};
    \addplot+ [polar comb, red, line width=3pt, mark=none, ->]
    coordinates {(90,11.4) (270,10.6)};
    \addplot+ [mark=none, ->, polar comb, blue, line width=3pt]
    coordinates {(30,5.3) (60,5.5) (120,4.0) (150,6.6) (210,5.2) (240,5.5) (300,3.4) (330,5.2)};
    \end{polaraxis}
\end{tikzpicture}
\end{document}

enter image description here

Issues:

  1. The labels (nodes near coords) are also shown as log value. I just want log-scale of the y-axis, keeping the presented y values as are.
  2. Many errors (on overleaf) regarding floating point: : Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `2.75998000000000'. The unreadable part was near '2.75998000000000'..
user-ik
  • 121
  • 3

1 Answers1

3

I believe that you can take advantage of the point meta, y coord trafo and y coord inv trafo keys.

y coord trafo and y coord inv trafo can apply a transformation on original y coordinates in order to modify the actual plot coordinates and associated tick labels. This is further explained in the pgfplots manual section 4.21 Symbolic Coordinates and User Transformations.

Basically what happens is

  • y coord trafo/.code = {<expression>} takes the input y coordinates and parses <expression> using them;
  • y coord inv trafo/.code = {<inv expression>} takes the results of the previous parse and parses <inv expression> with them;
  • point meta = <setting> sets the value of pgfplotspointmeta depending on the value of <setting>. As here you are interested in the y values, you could select <setting>=y, but since the y coordinates are parsed this would actually result in a bad output, so one can select rawy which corresponds to the actual unprocessed y values.

Here is the code

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymin=1, ymax=70,
        xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
        point meta ={rawy},
        y coord trafo/.code =\pgfmathparse{log10(#1)},
        y coord inv trafo/.code=\pgfmathparse{10^#1},
        nodes near coords style={font=\footnotesize},
        nodes near coords=\pgfmathprintnumber\pgfplotspointmeta\%,
        visualization depends on={x\as\myx},
        nodes near coords style={anchor=\myx-180},
    ]
    \addplot+ [polar comb, green, line width=3pt, mark=none, ->]
    coordinates {(0,21.6) (180,15.8)};
    \addplot+ [polar comb, red, line width=3pt, mark=none, ->]
    coordinates {(90,11.4) (270,10.6)};
    \addplot+ [mark=none, ->, polar comb, blue, line width=3pt]
    coordinates {(30,5.3) (60,5.5) (120,4.0) (150,6.6) (210,5.2) (240,5.5) (300,3.4) (330,5.2)};
    \end{polaraxis}
\end{tikzpicture}
\end{document}

And the ouput. I just removed the settings hiding the y axis so that you see the effect on the tick labels.

enter image description here

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • Excellent solution. Thanks! I struggle, however in integrating it with another solution: https://tex.stackexchange.com/questions/538220/logarithmic-y-axis-colors-arrow-heads-in-pgfplots-polar-charts – user-ik Apr 12 '20 at 16:55
  • You shouldn't have deleted the answer to the other question. Please see this comment. You could also just post an answer there, then both of us have an answer... (I still think that the anchor adjustment in my answer is also helpful... ;-) –  Apr 12 '20 at 19:36
  • 1
    @Schrödinger'scat will do ! – BambOo Apr 12 '20 at 20:27