我想在左边写“A”,在右边写“B”,然后在轴上删除(1,2,3,..),然后 分别在轴的左侧和右侧放置$\frac{-\varepsilon}{2}$
和插入。$\frac{\varepsilon}{2}$
x
\documentclass[12pt]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
xmin=-8,
xmax=8,
ymin=-1,
ymax=5,]
\draw[line width=2pt,color=blue,smooth,samples=50,domain=-8:8] plot(\x,{abs(1/(\x))});
\end{axis}
\end{tikzpicture}
\end{document}
答案1
pgfplots
这是一个真正使用命令并添加填充的版本。
\documentclass[12pt]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm]
\begin{axis}[unbounded coords=jump,
x=1cm,y=1cm,
axis lines=middle,
xmin=-8,
xmax=8,
ymin=-1,
ymax=5,xtick={-1,1},xticklabels={$\frac{-\varepsilon}{2}$,$\frac{\varepsilon}{2}$},
ytick=\empty]
\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1,name
path=left] {abs(1/x)} node[pos=0.05,above]{$A$};
\addplot[line width=2pt,color=blue,smooth,samples=51,domain=0.1:8,name
path=right] {abs(1/x)} node[pos=0.95,above]{$B$};
\path [name path=aux] (\pgfkeysvalueof{/pgfplots/xmin},8) -- (\pgfkeysvalueof{/pgfplots/xmax},8);
\addplot [pattern=horizontal lines,pattern color=black]
fill between [of=aux and left,soft clip={domain=-8:0}, ];
\addplot [pattern=north east lines,pattern color=black]
fill between [of=aux and right,soft clip={domain=0:8}, ];
\end{axis}
\end{tikzpicture}
\end{document}