如何在旋转的极轴环境中改变(控制)图例的位置?(例如转移到东南角?)
\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}
答案1
要将其从默认位置移开,请使用xshift
和/或yshift
内部legend style
键,如下所示:
(您也可以通过这种方式使用轴坐标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}
答案2
您可以使用以下方式将图例定位到相对于轴的位置(无需对任何长度进行硬编码):
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}