4

I am generating polar contour plots. In my industry, it is convention to put 0 degrees on the bottom rather than the right. My initial attempt was to use rotate=-90 within the polaraxis environment, which aligns the axis properly. However, this misaligns the contour plot (data is in the wrong place). I was able to fix it by adding rotate=45 to the \addplot3 options, which seems very weird to me. Does anyone have an idea why this is happening and what the proper way is to rotate a polar contour plot?

My pgf settings are as follows:

\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepgfplotslibrary{colorbrewer}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16,
             cycle list/Dark2}
\tikzexternalize

Un-rotated plot (notice how the lowest region points towards 270 degrees):

\begin{tikzpicture}
\begin{polaraxis}[
width=4in,
height=4in,
tickwidth=0,
xtick distance = 45,
separate axis lines,
y axis line style= { draw opacity=0 },
yticklabels = {},
ymin=0, ymax=1,
colorbar,
colorbar style={
    tickwidth=0,
    ylabel={Nondimensional blade lift, $\dfrac{L'}{\rho a c \left(\Omega R\right)^2}$},
},
colormap name={viridis},
axis on top=true,
]   
\addplot3 [contour filled={number=15}] file {fig/contour.dat};
\end{polaraxis}
\end{tikzpicture}

Un-rotated plot

My first attempt at rotating (notice how the lowest region now points towards 180 degrees, which is incorrect):

\begin{tikzpicture}
\begin{polaraxis}[
width=4in,
height=4in,
tickwidth=0,
xtick distance = 45,
separate axis lines,
y axis line style= { draw opacity=0 },
yticklabels = {},
ymin=0, ymax=1,
colorbar,
colorbar style={
    tickwidth=0,
    ylabel={Nondimensional blade lift, $\dfrac{L'}{\rho a c \left(\Omega R\right)^2}$},
},
colormap name={viridis},
axis on top=true,
rotate=-90,
]   
\addplot3 [contour filled={number=15}] file {fig/contour.dat};
\end{polaraxis}
\end{tikzpicture}

First attempt at rotating

Somehow this fixes the issue:

\begin{tikzpicture}
\begin{polaraxis}[
width=4in,
height=4in,
tickwidth=0,
xtick distance = 45,
separate axis lines,
y axis line style= { draw opacity=0 },
yticklabels = {},
ymin=0, ymax=1,
colorbar,
colorbar style={
    tickwidth=0,
    ylabel={Nondimensional blade lift, $\dfrac{L'}{\rho a c \left(\Omega R\right)^2}$},
},
colormap name={viridis},
axis on top=true,
rotate=-90,
]   
\addplot3 [contour filled={number=15}, rotate=45] file {fig/contour.dat};
\end{polaraxis}
\end{tikzpicture}

Fixed somehow

Needless to say, I'm confused. What is going on here and what's the right way to do it? Thanks in advance.

Edit: Forgot to provide contour.dat. Uploaded here: https://pastebin.com/7rXjLUr3

  • Welcome! I feel your post will be appreciated even more if you either provide us with the contents of fig/contour.dat, or just plot something that does not rely on it, such that others could play with your codes. The technical reason is that you are not supposed to transform plots like this, and apparently the rotation gets applied twice on the labels. You can find more on this e.g. here. – user194703 Oct 2 '19 at 23:33
  • Sorry, should've remembered to provide it. I've uploaded it here: pastebin.com/7rXjLUr3 – jnrobinson Oct 3 '19 at 0:40
2

For your convenience I added a style, rotate polar axis, that does the rotation and fixes the ticks. For the sake of reproducibility I refrain from using huge data files.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16}
\pgfplotsset{rotate polar axis/.style={rotate=#1,xticklabel
style={anchor=\tick+#1+180}}}
\begin{document}
\foreach \X in {0,90,180,270}
{\begin{tikzpicture}
\begin{polaraxis}[rotate polar axis=\X,
width=4in,
height=4in,
tickwidth=0,
xtick distance = 45,
separate axis lines,
y axis line style= { draw opacity=0 },
yticklabels = {},
ymin=0, ymax=1,
axis on top=true, 
] 

    \addplot coordinates {
        (0,1) (90,1/2) (180,1/3) (270,1/4)
    };  
\end{polaraxis}
\node at (current axis.north) [above=1em]{\texttt{rotate polar axis=\X}};
\end{tikzpicture}}
\end{document}

enter image description here

  • I just tried this and it's creating the same results as the incorrect second plot I included in my original question. The labels are correct now but the contour data itself is misaligned with the axes still. – jnrobinson Oct 3 '19 at 2:52
  • 1
    @jnrobinson If you do not get the same results as are shown above, then I cannot say much. – user194703 Oct 3 '19 at 3:02
  • I get the same results as you when I use the simple line plot you posted, but when I use the contour plot I originally asked the question about, the results are incorrect. – jnrobinson Oct 3 '19 at 12:08
0

Looks like no one has a suitable answer for this.

For future reference, Schrodinger's style macro works great for fixing the label rotation issue but doesn't fix the data misalignment issue.

I'll keep using rotate=45 in the addplot3 options for lack of a better fix

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.