13

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}
4
  • Second problem: add \begin{polaraxis}[ ..., ymin = 0, ymax = 8, ...] 3.problem: use \begin{tikzpicture}[scale=0.66] 4.problem?: remove \addplot[black] {4.05};.
    – Bobyandbob
    Apr 28, 2017 at 14:33
  • @Bobyandbob Yes, including ymin=0 and ymax=8 displays a "polar plane" that includes those points within a distance of 8 from the origin.
    – user74973
    Apr 28, 2017 at 17:41
  • @Bobyandbob I do not want to use scale=0.66 because it also scales the labels for the angles. Do you know how to specify the dimensions of the "polar plane" in units of centimeters or inches?
    – user74973
    Apr 28, 2017 at 17:41
  • @Bobyandbob I forgot to include the domain for the plot of the circle in the command \addplot {4.05};. (I had 4.05, but I should have had 8.05.) 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?
    – user74973
    Apr 28, 2017 at 17:41

2 Answers 2

12
+50

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}

5
  • The default domain is -5:5. My bad.
    – Symbol 1
    May 1, 2017 at 0:00
  • Are you saying that the default domain is -5:5 in TikZ for the \addplot command of any polar function?
    – user143462
    May 2, 2017 at 14:25
  • @Symbol 1 I see that x axis line style={double=lightgray,double distance=1pt} gives the border to the graph that I had requested.
    – user74973
    May 2, 2017 at 17:09
  • I modified your commands for drawing the axes: \draw[latex-latex](0,-9.5)--(0,9.5) node[below right]{\textit{x}} and \draw[latex-latex](-90,9.5)--(90,9.5) node[above right]{\textit{y}}.
    – user74973
    May 2, 2017 at 17:09
  • @user143462 That is right. The package will check if /pgfplots/domain is empty. If it is empty, then /tikz/domain will be used. And the default of the later is -5:5.
    – Symbol 1
    May 2, 2017 at 17:53
5

While you are waiting for some pgfplots support, here is an alternative using Metapost wrapped up in luamplib. You have to draw it all yourself, but you can get it looking exactly how you want. enter image description here

\documentclass{amsart}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\[
\begin{mplibcode}
beginfig(1);
    % set a unit so that 16u is 2/3 of the text width
    numeric u;
    16u = 2/3 \mpdim\textwidth;

    % define some paths
    path curve, circle, common; 
    curve = (for t=0 upto 359: (4-2*sind(t)) * dir t -- endfor cycle) scaled u;
    circle = fullcircle rotated 90 scaled 6u;
    common = buildcycle(curve, circle);

    % fill the common area first
    fill common withcolor 7/8[3/4 red,white];

    % now make the grey parts of the polar grid
    drawoptions(withpen pencircle scaled 1/4 withcolor 3/4 white);
    for t=0 step 45/4 until 359:
        draw ((4,0) -- (8u,0)) rotated t;
    endfor
    for r=1 upto 7:
        draw fullcircle scaled (2r*u);
    endfor

    % and the black parts of the polar grid
    drawoptions(withpen pencircle scaled 1/4);
    for t=0 step 45 until 179:
        draw (left--right) scaled 8.2u rotated t;
    endfor
    % including a double circle on the outside
    draw fullcircle scaled 16u;
    draw fullcircle scaled (16u+2);
    % grid labels
    drawoptions();
    label("$\frac{ \pi}4$", (9u,0) rotated 45);
    label("$\frac{3\pi}4$", (9u,0) rotated (3*45));
    label("$\frac{5\pi}4$", (9u,0) rotated (5*45));
    label("$\frac{7\pi}4$", (9u,0) rotated (7*45));

    % finally draw the curve and the marker circle
    draw curve withcolor 2/3 red;
    draw circle withcolor 2/3 blue;

endfig;
\end{mplibcode}
\]
\lipsum[2]
\end{document}

Notes

  • With luamplib you can access LaTeX variables, such as \textwidth using the \mpdim feature, which was borrowed from @egreg's gmp package.

  • I've put the graphic inside a math display \[ ... \] simply to get it centred on the page with a nice amount of skip before and after. Purists might prefer to use a center environment.

  • You will see that I've used buildcycle to define the common area to be filled. This is a pretty general purpose macro for defining paths like this, but when you use it with two closed paths you have to ensure that the starting point of each path is not inside the other one. That's why I've rotated the circle path by 90.

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.