% \usepackage{tikz}
% \usetikzlibrary{arrows,external}
% \usepackage{pgfplots}
% \pgfplotsset{compat=1.3}
% \usepgfplotslibrary{polar}
% \usepackage[detect-family]{siunitx}
% \usepackage[eulergreek]{sansmath}
% \sisetup{text-sf=\sansmath}
% \usepackage{relsize}
%
{%- if external_filename %}
    \tikzsetnextfilename{ {{ external_filename }} }
{%- endif %}
\pgfkeysifdefined{/artist/width}
    {\pgfkeysgetvalue{/artist/width}{\defaultwidth}}
    {\def\defaultwidth{ {{ width }} }}
\pgfkeysifdefined{/artist/height}
    {\pgfkeysgetvalue{/artist/height}{\defaultheight}}
    {%- if height %}
        {\def\defaultheight{ {{ height }} }}
    {%- else %}
        {\def\defaultheight{ {{ width }} }}
    {%- endif %}

\let\ytickshift\relax
\newlength{\ytickshift}
\pgfmathsetlength{\ytickshift}{-.5*\defaultheight-.75cm}

\begin{sansmath}
\begin{tikzpicture}[
        font=\sffamily,
        every pin/.style={inner sep=2pt, font={\sffamily\smaller}},
        every label/.style={inner sep=2pt, font={\sffamily\smaller}},
        every pin edge/.style={<-, >=stealth', shorten <=2pt},
        pin distance=2.5ex,
    ]
    \begin{polaraxis}[
            axis background/.style={ {{ axis_background }} },
            grid style={opacity=.3},
            xmode={{ xmode }},
            ymode={{ ymode }},
            width=\defaultwidth,
            {%- if height %}
                height=\defaultheight,
            {%- endif %}
            axis equal={{ axis_equal | lower }},
            y axis line style={yshift=-.5*\defaultheight},
            major y tick style={yshift=-.5*\defaultheight},
            %
            title={ {{ title }} },
            %
            xlabel={},
            ylabel={ {{ ylabel }} },
            xlabel style={xshift=.25*\defaultwidth,
                          yshift=-.06*\defaultheight,
                          rotate=-45},
            ylabel style={rotate=-90, yshift=-.5cm},
            %
            xmin={ {{ limits.xmin }} },
            xmax={ {{ limits.xmax }} },
            ymin={ {{ limits.ymin }} },
            ymax={ {{ limits.ymax }} },
            %
            xtick={ {{ ticks.x | join(', ') }} },
            ytick={ {{ ticks.y | join(', ') }} },
            {%- if ticks.xlabels %}
                xticklabels={ {{ ticks.xlabels | join(', ') }} },
            {%- endif %}
            {%- if ticks.ylabels %}
                yticklabels={ {{ ticks.ylabels | join(', ') }} },
            {%- endif %}
            {%- if ticks.xsuffix %}
                xticklabel=$\pgfmathprintnumber{\tick}{{ ticks.xsuffix }}$,
            {%- endif %}
            {%- if ticks.ysuffix %}
                yticklabel=$\pgfmathprintnumber{\tick}{{ ticks.ysuffix }}$,
            {%- endif %}
            yticklabel shift={\ytickshift},
            xticklabel shift={0.075cm},
            %
            ytick align=outside,
            xtick align=inside,
            max space between ticks=40,
            every tick/.style={},
            axis on top,
        ]

        % hack to calculate the position for the xlabel
        \coordinate (C) at ([rotate=-45,yshift=1.5cm] xticklabel* cs: 0);

        {% include 'subplot.tex' %}

    \end{polaraxis}

    % hack to draw the xlabel without being clipped
    \node[rotate=-45] at (C) { {{ xlabel }} };

\end{tikzpicture}
\end{sansmath}
