2

I would like to plot a polar plot in dB scaling, in this case I have positive and negative values. Usually a negative radius is plotted in the opposite direction, but with the help of transforming the coordinates I get the result I want.

But now there exists the problem that the negative and positive ticks are not perfectly aligned. I tried a hint but this only corrects the offset a bit. This could be due to the fact that the solution was given for a rotating ticks problem.

How can I get the radius axis ticks correctly aligned?

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}

\begin{document}
\begin{tikzpicture}
  \begin{polaraxis}[%
      xtick={0,30,...,180},
      ymin=-25,
      ymax=10,
      xmax=180,
      y coord trafo/.code=\pgfmathparse{#1+25},
      y coord inv trafo/.code=\pgfmathparse{#1-25},
      xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
      yticklabel style={yshift=-0.5cm},
    ],
    \addplot[%
    ]
    coordinates{%
      (0,-15)
      (30,-5)
      (90,0)
      (120,5)
    };
  \end{polaraxis}
\end{tikzpicture}
\end{document}
  • I am not sure what you think is misaligned. I think you mean that the negative yticklabels are a bit shifted to the right, right? But in fact the nodes are perfectly centered when you take the minus sign into account. To show that, you can add draw=red to the yticklabel style options. (And I recommend using anchor=near yticklabel opposite instead of yshift.) – Stefan Pinnow Nov 15 '16 at 17:17
  • Did my tip help you or do you need further assistance? – Stefan Pinnow Nov 19 '16 at 18:40
  • Thank you very much, I tried to use anchor=below which is not allowed. An anchor=north also seems to yield the same result. If you post this as an answer, I will accept it. Thank you very much. – Roos Nov 21 '16 at 14:23
2

As already mentioned in the comment below the question, the tick labels are perfectly aligned. Have a look at the comments in the code for more details.

\documentclass{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{polar}
\begin{document}
    \begin{tikzpicture}
        \begin{polaraxis}[
            ymin=-25,
            ymax=10,
            xmax=180,
            % when you have at PGFPlots v1.13 you can use the `xtick distance' feature
%            xtick={0,30,...,180},
            xtick distance=30,
            y coord trafo/.code=\pgfmathparse{#1+25},
            y coord inv trafo/.code=\pgfmathparse{#1-25},
            xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
            yticklabel style={
                % draw a frame around the tick labels to see, that they are
                % indeed centered
                draw=red,
                % (and use there is a better way to position the tick labels
                % on the other side of the axis ...)
%                yshift=-0.5cm,
                anchor=near yticklabel opposite,
            },
        ],
            \addplot coordinates {
                (0,-15) (30,-5) (90,0) (120,5)
            };
        \end{polaraxis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.