2

How to draw the following figure using Tikz/pgf plot ?

enter image description here

I have tried he following code and got the below figure:

\begin{tikzpicture} 
    \draw[solid] (0,-1) circle (1); 
    \draw[solid] (0,-1) circle (2);
     \path [draw=none, fill=blue, even odd rule, fill opacity = 0.5] (0,-1) circle (2) (0,-1) circle (1);
    \draw[solid, shift={(6 cm,1 cm)}] (2,-2) circle (1);
    \draw[solid, shift={(6 cm,1 cm)}] (2,-2) circle (2);

    \end{tikzpicture}

enter image description here

But how to fill the 2nd annular region, how to draw the map f, how to draw the text A, B, A-B ??

Please help me to draw the first figure.

Update:

Using the following script by @Zarko,


\fbox{
    \begin{tikzpicture}
    % circles
    \draw [fill=blue!50, even odd rule] 
    (0,0) ellipse[x radius = 3, y radius=2, rotate=20] circle[radius=1] node {$B$};
    \draw [fill=blue!50, even odd rule]
    (7,0) ellipse[x radius = 3, y radius=2, rotate=35] circle (1) node {$D$};
    % labels
    \path   (0,1.5) node {$A-B$}  
    (0,2) node[above] {$A$}
    (7,2.2) node[above] {$C$};
    % arrow
    \draw[->]   (1.5,0.5) -- node[pos=0.35,above] {$f$}  (7,0.5);
    \draw [-to,shorten >=-1pt,black, thick] (1.5,0.5) -- (7,0.5);
    \end{tikzpicture}
      }

enter image description here

But I need the points on the axes as well.

I use the following Latex package:

\documentclass[12pt,leqno]{amsart}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\topmargin=0.02cm
\textwidth =  17cm
\textheight = 23cm
\baselineskip=11pt
%
\setlength{\oddsidemargin}{0.01 pt}
\setlength{\evensidemargin}{0.01 pt}
\renewcommand{\baselinestretch}{1.4}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{graphicx}
\graphicspath{ }
\usepackage{epstopdf}
\usepackage{csquotes}
\usepackage{wrapfig}
\usepackage{accents}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{calligra}
\usepackage[colorlinks]{hyperref}
\hypersetup{citecolor=black}
\newtheorem{fig}{figure}[section]
\numberwithin{figure}{section}
\newcommand\norm[1]{\left\lVert#1\right\rVert}

\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}{Corollary}[thm]
\theoremstyle{definition}
\newtheorem{defn}{Definition}[section]
\newtheorem{conj}{Conjecture}[section]
\newtheorem{exmp}{Example}[section]

\theoremstyle{remark}
\newtheorem*{rem}{Remark}
\newtheorem*{note}{Note}
\usepackage{mathtools}
\makeatletter
\begin{document} 
\end{document}

2 Answers 2

4

enter image description here

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
% circles
\draw [fill=blue!50, even odd rule] 
    (0,0) circle (2) circle (1) node {$B$};
\draw [fill=blue!50, even odd rule]
    (6,0) circle (2) circle (1) node {$B$};
% labels
\path   (0,1.5) node {$A-B$}  
        (0,2) node[above] {$A$}
        (6,2) node[above] {$A$};
% arrow
\draw[->]   (1.5,0.5) -- node[pos=0.35,above] {$f$}  (6,0.5);
    \end{tikzpicture}
\end{document}

Addendum: with ellipses and changed shapes' labels:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
% circles
\draw [fill=blue!50, even odd rule] 
    (0,0) ellipse[x radius = 3, y radius=2, rotate=15] circle[radius=1] node {$B$};
\draw [fill=blue!50, even odd rule]
    (7,0) ellipse[x radius = 3, y radius=2, rotate=30] circle (1) node {$D$};
% labels
\path   (0,1.5) node {$A-B$}  
        (0,2) node[above] {$A$}
        (7,2.2) node[above] {$C$};
% arrow
\draw[->]   (1.5,0.5) -- node[pos=0.35,above] {$f$}  (7,0.5);
    \end{tikzpicture}
\end{document}

enter image description here


\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
% circles
\draw [fill=blue!50, even odd rule] 
    (0,0) ellipse[x radius = 3, y radius=2, rotate=15] circle[radius=1] node {$B$};
\draw [fill=blue!50, even odd rule]
    (7,0) ellipse[x radius = 3, y radius=2, rotate=30] circle (1) node {$D$};
% labels
\path   (0,1.5) node {$A-B$}  
        (0,2) node[above] {$A$}
        (7,2.2) node[above] {$C$};
% arrow
\draw[->]   (1.5,0.5) -- node[pos=0.35,above] {$f$}  (7,0.5);
    \end{tikzpicture}
\end{document}
9
  • I think the OP wanted to achieve the first drawing at the top, so the second right ring should be filled too. :D
    – Alenanno
    Oct 14, 2020 at 6:59
  • 1
    @Alenanno, you are right. I will corrected answer asap.
    – Zarko
    Oct 14, 2020 at 7:27
  • @Zarko, thanks. I have few questions: (1) how to replace the outside circle by an ellipse? (2) how to replace the right hand side texts A and B by C and D respectively ?
    – MAS
    Oct 14, 2020 at 8:51
  • @Zarko, Thank you very much. Finally how to box the whole figure in box axis frame? \begin{axis} ---\end{axis} is not giving the result ? I think we need to arrange the coordinates and labels
    – MAS
    Oct 14, 2020 at 11:59
  • @M.A.SARKAR, you are not ending story :-(! You should be more clear in at writing of your question! Try to insert image in the \fbox (using standalone document class you need to add option preview to it}
    – Zarko
    Oct 14, 2020 at 12:13
3

I propose this short code with pstricks:

\documentclass[border=5pt, svgnames]{standalone}
\usepackage{pst-node}
 \begin{document}

\begin{pspicture}(-1.5,-1.6)(8,2)
    \psset{unit=0.8cm, fillcolor = ForestGreen!70,fillstyle = solid}
    \SpecialCoor\small 
    $ \multirput(0,0)(8,0){2}{\psRing(0,0){1}{2}\rput(0,0){B}\rput(0.5,2.4){A}}
    \rput{30}(1.45;140){A-B}
    \psset{labelsep=2pt, shortput=nab, npos=0.4, arrowinset=0.12}
    \pnodes{A}(1.4,0.5)(7.8,0.5)\ncline{->}{A0}{A1}^{f} $
\end{pspicture}

\end{document} 

enter image description here

5
  • Thank you very much. However, I use \documentclass[12pt,leqno]{amsart}. I tried your code but not compatible with mydocument class. Any help?
    – MAS
    Oct 14, 2020 at 12:54
  • Why not compatible with the class?
    – Bernard
    Oct 14, 2020 at 12:58
  • I am not sure but I tried and failed. May be my latex package is old. You can see in my edited question, the latex package which i am using.
    – MAS
    Oct 14, 2020 at 13:14
  • 1
    Ì guess it is aproblem of compiling engine: pstricks doesn't work with pdflatex (this engine cannot make the calculations required by postscript), so you have to either follow the traditional way: latex ->dvips->pstopdf, or compile with xelatex, which has no problem.
    – Bernard
    Oct 14, 2020 at 13:28
  • ok,thank you very much.I will try
    – MAS
    Oct 14, 2020 at 13:33

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.