我有一个简单的四分之一极坐标图,我想将其旋转 -90°。但是,这样做会在图和其标题之间插入一个很大的间隙。当我将图旋转 +90° 时不会发生这种情况。这是 pgfplots 中的错误吗?
以下是 MWE:
\documentclass[]{article}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.49\columnwidth}
\centering
\begin{tikzpicture}
\begin{polaraxis}[xmin=0,xmax=90,ymin=0,ymax=1,rotate=90,x dir=reverse,domain=0:90,no markers, yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}%
\caption{Positive $90^\circ$ rotation}
\end{subfigure}
\begin{subfigure}[t]{0.49\columnwidth}
\centering
\begin{tikzpicture}
\begin{polaraxis}[xmin=0,xmax=90,ymin=0,ymax=1,rotate=-90,x dir=reverse,domain=0:90,no markers,yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}%
\caption{Negative $90^\circ$ rotation (adds gap)}
\end{subfigure}
\caption{Rotation of a polar graph}
\end{figure}
\end{document}
答案1
以下是对齐两张图片的一些技巧
clip=false
将密钥添加到正确的polaraxis
环境。- 定义为 左图的右侧,其中
baseline
是左轴的名称tikzpicture
outer south
baseline=s.outer south
s
\documentclass[]{article}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.49\columnwidth}
\centering
\begin{tikzpicture}
\begin{polaraxis}[name=s,xmin=0,xmax=90,ymin=0,ymax=1,rotate=90,x dir=reverse,domain=0:90,no markers, yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}%
\caption{Positive $90^\circ$ rotation}
\end{subfigure}
\begin{subfigure}[t]{0.49\columnwidth}
\centering
\begin{tikzpicture}[baseline=(s.outer south)]
\begin{polaraxis}[clip=false,xmin=0,xmax=90,ymin=0,ymax=1,rotate=-90,x dir=reverse,domain=0:90,no markers,yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}%
\caption{Negative $90^\circ$ rotation (adds gap)}
\end{subfigure}
\caption{Rotation of a polar graph}
\end{figure}
\end{document}
答案2
在这里,我将第二个设置tikzpicture
为临时值\box0
,然后使用\smash{\raisebox{-.45\ht0}{\copy0}}
编辑:但是,上述方法似乎破坏了居中。因此,\centering
我没有在此子图中使用,而是使用了\hfil\smash{\raisebox{-.45\ht0}{\copy0}}\hfill
。
\documentclass[]{article}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{polar}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.49\columnwidth}
\centering
\begin{tikzpicture}
\begin{polaraxis}[xmin=0,xmax=90,ymin=0,ymax=1,rotate=90,x dir=reverse,domain=0:90,no markers, yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}%
\caption{Positive $90^\circ$ rotation}
\end{subfigure}
\begin{subfigure}[t]{0.49\columnwidth}
\setbox0=\hbox{\begin{tikzpicture}
\begin{polaraxis}[xmin=0,xmax=90,ymin=0,ymax=1,rotate=-90,x dir=reverse,domain=0:90,no markers,yticklabels={}]]
\addplot [thick, smooth] {cos(x)};
\end{polaraxis}
\end{tikzpicture}}\hfil\smash{\raisebox{-.45\ht0}{\copy0}}\hfill%
\caption{Negative $90^\circ$ rotation}
\end{subfigure}
\caption{Rotation of a polar graph}
\end{figure}
\end{document}