8

I am trying to graph two circles on the same page so that the x-axes of both graphs are aligned and the y-axes of both graphs are the same height. (Maybe the appearance of these would not look nice with x-axes aligned.) The first circle is to have radius 3, and the second circle is to be dashed and to have radius 5/4; not to waste space, the scaling on the first graph is to be less than the scaling for the second graph. Maybe include five tick marks along axes a unit apart in first graph and three tick marks a half-a-unit apart in second graph. I would like diagonal hatching for shading. In the first graph, shading should be inside the circle, and in the second graph, shading should be outside the circle. (I looked on page 217 of tikzpgfmanual.pdf for drawing diagonal hatch lines. They are not there. Please indicate how to separate hatch lines.) I included some of the suggested code. I did not find a manual for including tick marks on the axes. When shading, do you usually include arrows on axes?

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,angles,quotes}


\begin{document}


$\{(x, \, y) \mid \vert x^{2} + (y - 1)^{2} \vert \leq 3\}$ \\
\begin{tikzpicture}[dot/.style={draw,fill,circle,inner sep=1pt}]
  \draw[<->] (-4,0) -- (4,0) node[below] {$x$};
  \draw[<->] (0,-3) -- (0,5) node[left] {$y$};
\end{tikzpicture}


$\{(x, \, y) \mid x^{2} + y^{2} > 5/4\}$ \\
\begin{tikzpicture}[dot/.style={draw,fill,circle,inner sep=1pt}]
  \draw[<->] (-2,0) -- (2,0) node[below] {$x$};
  \draw[<->] (0,-2) -- (0,2) node[left] {$y$};
\end{tikzpicture}


\end{document}
  • I'm assuming the second tikzpicture is actually the first circle, that you're referring to? – 1010011010 Aug 4 '14 at 19:20
11

Is it something like this what you want to achieve?

enter image description here

The code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{patterns}

\newcommand\drawticks[1]{
\foreach \Valor in {-#1,...,#1}
  {
  \draw ([yshift=2pt]\Valor,0) -- ([yshift=-2pt]\Valor,0);  
  \draw ([xshift=2pt]0,\Valor) -- ([xshift=-2pt]0,\Valor);  
  }
}

\begin{document}

\begin{center}
\begin{tikzpicture}[
dot/.style={
  fill,
  circle,
  inner sep=1pt
  }
]
\begin{scope}[x=0.4cm,y=0.4cm]
\draw[<->] 
  (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] 
  (0,-5) node (yaxisl1) {} -- (0,5) node[left] {$y$};
\fill[pattern=north west lines,opacity=.6,draw] 
  (0,1) circle [radius=3];
\node[anchor=north] 
  at (yaxisl1.south) 
  (label1)
  {$\{(x, \, y) \mid \vert x^{2} + (y - 1)^{2} \vert \leq 3\}$};
\drawticks{4}
\node[dot,label={left:$(0,1)$}]
  at (0,1) {};
\draw[thin] 
  (0,1) -- node[below] {3} ++(45:3);
\end{scope}

\begin{scope}[xshift=7cm]
\clip
  (-2.2,-2) rectangle (2.2,2.2);
\fill[pattern=north west lines,opacity=0.6]
  (current bounding box.north west)
  rectangle
  (current bounding box.south east);
\end{scope}
\begin{scope}[xshift=7cm]
\draw[dashed,fill=white] (0,0) circle [radius=5/4];
\draw[<->] (-2,0) -- (2,0) node[below] {$x$};
\draw[<->] (0,-2) node (yaxisl2) {} -- (0,2) node[left] {$y$};
\node[anchor=north] 
  at (yaxisl2.south|-yaxisl1.south) 
  {$\{(x, \, y) \mid x^{2} + y^{2} > 5/4\}$};
\drawticks{1}
\node[dot]
  at (0,0) {};
\draw[thin] 
  (0,0) -- node[above] {$\frac{5}{4}$} ++(45:5/4);
\end{scope}
\end{tikzpicture}
\end{center}

\end{document}
  • Each graph is nice. They are missing the tick marks. 1010011010 gives the code for these. Is that what you use? I would like to have arrowheads at both ends of the axes, too. I wanted both graphs in the same row - with the heights and widths (of the pictured axes) the same. Since the radius of the first circle is much bigger than that of the second circle, and since the circle with the bigger radius is centered at (0,1), there has to be some scaling for the first graph. (The graph of the circle that you provide is centered at origin.) – user143462 Aug 6 '14 at 12:18
  • 1
    @user143462 In draw[<->] (0,-4) -- (0,4) node[left] (firstaxis) {$y$}; \node [above=0cm of firstaxis.north] {$a$}; The first \draw draws a line with arrow tips on both ends (due to [<->]) from (0,-4) to (0,4) and places a node called firstaxis at (0,4) with the label $x$ to its left. – Gonzalo Medina Aug 6 '14 at 17:32
  • 1
    @user143462 The second path places a node 0cm above of the north anchor of firstaxis with the label $a$. – Gonzalo Medina Aug 6 '14 at 17:33
  • 1
    @user143462 In my updated answer I introduced the modifications you suggested in comments and additionally I added some marking of the radii (this clarifies the situation, since otherwise the different scaling might produce confusion). – Gonzalo Medina Aug 6 '14 at 17:34
  • 1
    @user143462 In \draw[<->] (0,-5) node (yaxisl1) {} -- (0,5) node[left] {$y$}; this node (yaxisl1) {} puts a node at the initial point, called yaxisl1 (l for left 1 because I'll use a second such node for the other part of the picture) and with empty label; nodes must always have a label even if empty. – Gonzalo Medina Aug 6 '14 at 23:07
5

I had this. Or did you want them aligned vertically? I used landscape option from article class to show them aligned horizontally.

http://i.imgur.com/FFbJT85.png?1

\documentclass[landscape]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,angles,quotes,positioning,datavisualization, patterns}

\def\tickheight{2pt}
\def\tickamount{4}

\begin{document}
\begin{tikzpicture}

\scope
\clip[xshift=9cm] (-5,-5) rectangle (5,5)
      (0,0) circle (1);
\draw[xshift=9cm,pattern=north west lines,draw=none] (0,0) circle (3);
\endscope

\draw[<->] (-4,0) -- (4,0) node[below] {$x$};
\draw[<->] (0,-4) -- (0,4) node[left] (firstaxis) {$y$};

\draw (0,0) circle [radius=3cm];

\node [above=0cm of firstaxis.north] {First circle: $\{(x, \, y) \mid \vert x^{2} + (y + 1)^{2} \vert < 3\}$};

\draw[<->, xshift=9cm] (-4,0) -- (4,0) node[below] {$x$};
\draw[<->, xshift=9cm] (0,-4) -- (0,4) node[left] (secondaxis) {$y$};

\draw[xshift=9cm, dashed] (0,0) circle [radius=1cm];

\draw[pattern=north west lines,draw=none] (0,0) circle [radius=3cm];

\node [above=0cm of secondaxis.north] {Second circle: $\{(x, \, y) \mid x^{2} + y^{2} > 1\}$};

\foreach \i in {-\tickamount,...,\tickamount} {
\draw (\i,-\tickheight) -- (\i,\tickheight);
\draw (-\tickheight,\i) -- (\tickheight,\i);
\draw[xshift=9cm] (\i/2,-\tickheight) -- (\i/2,\tickheight);
\draw[xshift=9cm] (-\tickheight,\i/2) -- (\tickheight,\i/2);
}

\end{tikzpicture}
\end{document}
  • This is close to what I want. The center of the first circle should be (0,1). Look at the set. The radius of the second circle should be 5/4. Since the radii are quite different, I would like the distance between tick marks in the first graph to be less than half that in the second graph. The shading in the second graph should extend to the pictured Cartesian plane. So, it should look like a shaded square with a white circular center. Also, in the first picture, the axes should be extended a bit so that a tick mark is not at the ends. Please put the sets directly below the y-axis. Thanks. – user143462 Aug 5 '14 at 13:15

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.