4

I have a simple quarter polar plot that I would like to rotate by -90°. However, doing so inserts a large gap between the plot and its caption. That doesn't happen when I rotate the plot by +90°. Is it a bug in pgfplots?

Here is a 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}

enter image description here

1
  • Just add clip=false to the right polaraxis environment
    – Salim Bou
    Commented Aug 4, 2016 at 19:52

2 Answers 2

2

Here some tricks to align the two pictures

  • Add clip=false key to the right polaraxis environment.
  • Define baseline for the right tikzpicture to be outer south of the left picture with baseline=s.outer south where s is the name of the left axis

\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}

enter image description here

0
1

Here, I set the 2nd tikzpicture into temporary \box0 and then output it with \smash{\raisebox{-.45\ht0}{\copy0}}

EDIT: However, the above approach seemed to break centering. So, instead of using \centering in this subfigure, I used, instead, \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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .