[Tex/LaTex] Shading between the graphs of two polar equations in pgfplots

tikz-pgf

The following code displays the graph of the polar equation r(\theta) = 4 - 2*sin(\theta). I have the region bounded by this curve shaded. I want only the region bounded by this curve and the circle centered at 0 with radius 3 to be shaded.

The radius of the polar axis is 7. I did not specify this. Is the default value one more than the maximum radius of the graph? How do I get the radius of the polar axis to be 8?

I did not specify the dimensions of the plot. It is bigger than I want. How do I get it to be two-thirds the current display size? Can the dimensions be specified by specifying the number of centimeters or inches for the height and width?

Why is there a small black arc – maybe between -5 degrees and 5 degrees drawn at a radius slightly more than 4?

    \documentclass{amsart}
    \usepackage{amsmath}

    \usepackage{tikz}

    \usepackage{pgfplots}
    \usepgfplotslibrary{polar}
    \pgfplotsset{compat=1.11}


    \begin{document}


    \begin{tikzpicture}
    \begin{polaraxis}[
        clip=false, major grid style={black}, minor x tick num=3, % 3 minor x ticks between majors
        minor y tick num=2, % 2 minor y ticks between majors
        grid=both,
        xtick={0,45,...,315},
        xticklabels={, $\frac{\pi}{4}$, , $\frac{3\pi}{4}$, , $\frac{5\pi}{4}$, , $\frac{7\pi}{4}$},
        ytick={0,3,6},
        yticklabels={\empty}
    ]
      \addplot[samples=360, mark=none, fill=red!70!black, opacity=0.5, domain=0:360] {4 - 2*sin(\x)};
      \addplot[samples=360, mark=none, thick, red!70!black, domain=0:360] {4 - 2*sin(\x)};

\addplot[samples=360, draw=red, thick, mark=none, domain=0:360] {3};

      \addplot[black] {4.05};
    \end{polaraxis}

    \end{tikzpicture}

    \end{document}

Best Answer

There are so many minor questions. Tell me if any part in this answer is unclear.

I want only the region bounded by this curve and the circle centered at 0 with radius 3 to be shaded.

See the code at the end. Essentially you can either \clip or plot a new function min(4-2*sin(\x),3)

Is the default value one more than the maximum radius of the graph?

Noone really knows. The determination of the axis limit is a long-standing mystery of pgfplots.

How do I get the radius of the polar axis to be 8?

Answered by @Bobyandbob in the comment. (This is perhaps the least pathetic way to control the axis limit.)

Can the dimensions be specified by specifying the number of centimeters or inches for the height and width?

Use \begin{polaraxis}[width=5cm] or whatever value you want.

Why is there a small black arc - maybe between -5 degrees and 5 degrees drawn at a radius slightly more than 4?

Because \addplot[black] {4.05}; in your MWE. Recall that the default domain is -4:4 in TikZ.

How can I get the x-axis and y-axis drawn?

Strictly speaking in polaraxis there are only r-axis and θ-axis. To draw the usual x-axis, use \draw[->]. (See the code below.) The labels on the x-axis can be drawn by something like \draw foreach\x in{-10,...,10}{(0,\x)node[lower right]{x}};

I wanted two concentric circles of radii 8 and 8.05 to indicate the extent of the displayed "polar plane." The circle with a radius of 8 is drawn with minor x tick num=2. How do I get a circle with radius 8.05 or 8.1 with the same shade of gray to be drawn?

This can be done by TikZ's double. You can control it by line width and double distance. (See the code below.)

code

\documentclass{article}

\usepackage{pgfplots}
    \usepgfplotslibrary{polar}
    \pgfplotsset{compat=1.14}

\begin{document}
    \begin{tikzpicture}
        \begin{polaraxis}[
            width=5cm,
            clip=false,
            x axis line style={double=lightgray,double distance=1pt},
            grid=both,
            major grid style=black,
            minor x tick num=3, % 3 minor x ticks between majors
            minor y tick num=2, % 2 minor y ticks between majors
            xtick={0,45,...,315},
            xticklabels={,$\frac{\pi}4$,,$\frac{3\pi}4$,,$\frac{5\pi}4$,,$\frac{7\pi}4$},
            %y tick style={draw=none},
            yticklabel=\empty,
            domain=0:360,
            samples=360,
            mark=none
        ]
            \addplot[draw=red,thick]{3};
            \addplot[thick,fill=none,draw=red!70!black]{4-2*sin(\x)};
            \addplot[thick,fill=red!70!black,draw=none,opacity=0.5]{min(4-2*sin(\x),3)};
            \draw[->](0,-10)--(0,10);
            \draw[->](90,-10)--(90,10);
        \end{polaraxis}
    \end{tikzpicture}
\end{document}