4

How can I shift (control) the position of the legend within rotated polar axis environment? (e.g. shift into the south-east corner?)

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\definecolor{lgray}{rgb}{0.7,0.7,0.7}
\definecolor{dgray}{rgb}{0.3,0.3,0.3}
\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep=1pt,
        ellipse,
        anchor=\tick-(180-\pgftransform@angle)
    },
    yticklabel style={
        anchor=90 + \pgftransform@angle
    }
}
\makeatother
\begin{polaraxis}[
  rotate=-90,
  xmin=00,
  xmax=90,
  %xtick={0,30,60,90}
  xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
  xtick={0,15,...,90},
  ]  
\addplot[red,no markers,smooth] table{
   0 1
   30 2
   60 3
   90 2
    };    
\addlegendentry{Text1}
\addplot[no markers,smooth] table{
   0 2
   30 3
   60 1
   90 1
    };
\addlegendentry{Text2}
\end{polaraxis}
\end{tikzpicture}
\end{document}

enter image description here

  • Don't ask me to explain why this works, but a short experiment shows that you can get the legend where you want, if you add legend style={at={(1,2.1)}} directly after your xtick= line. – Thruston Nov 12 '13 at 12:29
3

To just shift it form its default position use xshift and/or yshift inside legend style key in this way:

enter image description here

(you can also use axis coordinate in this way legend style={anchor=north west, at={(axis cs:45,4)}})

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\definecolor{lgray}{rgb}{0.7,0.7,0.7}
\definecolor{dgray}{rgb}{0.3,0.3,0.3}
\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep=1pt,
        ellipse,
        anchor=\tick-(180-\pgftransform@angle)
    },
    yticklabel style={
        anchor=90 + \pgftransform@angle
    }
}
\makeatother
\begin{polaraxis}[
  rotate=-90,
  xmin=00,
  xmax=90,
  %xtick={0,30,60,90}
  xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
  xtick={0,15,...,90},
legend style={xshift=3.5cm,yshift=-.2cm}
%legend style={anchor=north west, at={(axis cs:45,4)}}
  ]  
\addplot[red,no markers,smooth] table{
   0 1
   30 2
   60 3
   90 2
    };    
\addlegendentry{Text1}
\addplot[no markers,smooth] table{
   0 2
   30 3
   60 1
   90 1
    };
\addlegendentry{Text2}
\end{polaraxis}
\end{tikzpicture}
\end{document}
|improve this answer|||||
  • nicely working, prefer the commented out line ...at={(axis cs:45,4)} – Thomas Nov 12 '13 at 15:05
4

You can position the legend relative to the axis using (without hard coding any lengths):

legend style={at=(current axis.south east), anchor=south west}


\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\definecolor{lgray}{rgb}{0.7,0.7,0.7}
\definecolor{dgray}{rgb}{0.3,0.3,0.3}
\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep=1pt,
        ellipse,
        anchor=\tick-(180-\pgftransform@angle)
    },
    yticklabel style={
        anchor=90 + \pgftransform@angle
    }
}
\makeatother
\begin{polaraxis}[
  rotate=-90,
  xmin=00,
  xmax=90,
  %xtick={0,30,60,90}
  xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
  xtick={0,15,...,90},
  legend style={at=(current axis.south east), anchor=south west}
  ]  
\addplot[red,no markers,smooth] table{
   0 1
   30 2
   60 3
   90 2
    };    
\addlegendentry{Text1}
\addplot[no markers,smooth] table{
   0 2
   30 3
   60 1
   90 1
    };
\addlegendentry{Text2}
\end{polaraxis}
\end{tikzpicture}
\end{document}
|improve this answer|||||
  • is nicely working, although better control by the following – Thomas Nov 12 '13 at 15:03

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.