2

I want to be able to plot the upper half of the attached polar plot (MWE), by setting xmin=0 and xmax=180. This, however, is non-trivial when I at the same time want to have the yaxis with labels and title as illustrated below. Is there a clean way of solving this without rotating the coordinate system (and the ylabel/yticklabels actually follows the replacement of the yaxis)?

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\pgfplotsset{compat=1.12}
\usepgfplotslibrary{polar}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
    \def\xshift{5cm}
    \begin{polaraxis}[
        xmin=90,
        xmax=450,
        major tick length=2,
        xtick={90,120,...,420},
        xticklabel={\pgfmathtruncatemacro{\mytick}{mod(\tick,360)}${\mytick}^\circ$},
        grid=both,
        y axis line style={xshift=-\xshift},
        ytick style={xshift=-\xshift},
        yticklabel style={
            xshift=-\xshift-0.3em,
        },  
        ymax=0.5,
        ytick={0,0.1,...,0.5},
        ylabel={Cumbersome label},
        every axis y label/.style={
            xshift=-\xshift-2.5em,
            yshift=1.4cm,
            rotate=90,
            anchor=south,
        },  
        ]
        \addplot+[mark=none,domain=90:450,smooth,blue,samples=1000] {sin(2*x)*cos(2*x)};
    \end{polaraxis}
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

In an attempt of providing a clean solution, consider the following

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\pgfplotsset{compat=1.12}
\usepgfplotslibrary{polar}

\begin{document}
\begin{figure}
    \centering
    \begin{tikzpicture}
    \def\xshift{5cm}
    \begin{polaraxis}[
        xmin=0,
        xmax=180,
        major tick length=2,
        xtick={0,30,...,180},
        xticklabel={\pgfmathtruncatemacro{\mytick}{mod(\tick,360)}${\mytick}^\circ$},
        grid=both,
        y axis line style={rotate=-90,yshift=-\xshift},
        ytick style={rotate=-90,yshift=-\xshift},
        yticklabel style={rotate=-90,yshift=-\xshift},  
        ymax=0.5,
        ytick={0,0.1,...,0.5},
        ylabel={Cumbersome label},
        every axis y label/.style={
            xshift=-\xshift,
            rotate=90,
            anchor=south,
        },  
        ]
        \addplot+[mark=none,domain=90:450,smooth,blue,samples=1000] {sin(2*x)*cos(2*x)};
    \end{polaraxis}
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

1

Don't know if this counts as clean, but rotating things around the axis origin might be an option.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplotstable}

\pgfplotsset{compat=1.12}
\usepgfplotslibrary{polar}

\begin{document}
    \begin{tikzpicture}
    \newcommand\xshift{5cm}
    \newcommand\AxisWidth{8cm}
    \begin{polaraxis}[
        xmin=0,
        xmax=180,
        scale only axis,  % set width of axis only to 
        width=\AxisWidth, % this value
        major tick length=2,
        xtick={0,30,...,180},
        xticklabel={\pgfmathtruncatemacro{\mytick}{mod(\tick,360)}${\mytick}^\circ$},
        grid=both,
        y axis line style={
           overlay, % added so it doesn't increase the size of the bounding box
           rotate around={90:(current axis.origin)}, % makes it a vertical line through the origin
           yshift=\xshift,  % shift left
           shorten >=\AxisWidth/4, % seemed to shorten line at both ends, so shorten by a quarter of the length
           xshift=\AxisWidth/4,    % and then shift it up
           line cap=rect
           },
        ytick style={rotate=-90,yshift=-\xshift},
        yticklabel style={
           rotate=-90, % first rotate nodes "in place"
           rotate around={90:(current axis.origin)}, % then rotate them around the origin
           xshift=-\xshift, % and move them left
           left, % set a useful anchor
           alias=ytick-\ticknum % give ticklabels nodes aliases
           },  
        ymax=0.5,
        ytick={0,0.1,...,0.51},
        ylabel={Cumbersome label},
        ylabel style={
           at=(current axis.west -| ytick-1.west), % place at y-coord of current axis.west, x-coord of of ytick-1
           left, % set useful anchor
           anchor=south,
           rotate=90
           }
        ]
        \addplot+[mark=none,domain=90:450,smooth,blue,samples=100] {sin(2*x)*cos(2*x)};
    \end{polaraxis}
    \end{tikzpicture}

\end{document}
  • This is much better, but still has the somewhat arbitrary command "left=2cm" in the ylabel style. I guess this value (2cm), "\AxisWidth" and "\xshift" should all be linked? – user2978680 Feb 11 at 20:43
  • @user2978680 Came up with a workaround for that, see updated answer. – Torbjørn T. Feb 11 at 20:49
  • Smooth! Completing with something like "\def\xshift{1.2*\AxisWidth/2}", and I think this is as good as it gets :) – user2978680 Feb 11 at 21:17
  • How come "\newcommand\temp{2*\baselineskip+\AxisWidth/2}" does not work? – user2978680 Feb 11 at 21:27
  • Separating into "\newcommand\temp{2.5*\baselineskip}" and "\newcommand\xshift{\AxisWidth/2}", and then replacing \xshift by \xshift+\temp solves that problem, but why? – user2978680 Feb 11 at 21:35

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.