如何使用 Tikz/pgf 图绘制下图?
我尝试了下面的代码并得到了下图:
\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}
但是如何填充第二个环形区域,如何绘制地图f
,如何绘制text
A、B、AB?
请帮我画出第一个图形。
更新:
使用@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}
}
但我也需要轴上的点。
我使用以下 Latex 包:
\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}
答案1
\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}
附录: 使用省略号和改变的形状标签:
\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}
\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}
答案2
我建议使用以下简短的代码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}