我试图在区间 -1,0 上绘制函数 1/((x+1)^{3/2}))。我想在 x=-1 处包含垂直渐近线,并遮蔽两个区间之间的区域。但是,我当前的代码不断出现错误:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{pict2e}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,arrows.meta}
\usetikzlibrary{shadows}
\usetikzlibrary{external}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}
\usepackage{xcolor}
\usepackage{nicefrac}
\begin{document}
\pgfplotsset{
standard/.style={
axis line style = thick,
trig format=rad,
enlargelimits,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin)},anchor=south east}
}
}
\begin{tikzpicture}
\begin{axis}[standard,
xtick={-1,0},
ytick=\empty,
samples=1000,
xlabel={$x$},
ylabel={$y$},
xmin=-1,xmax=0,
ymin=-0.05,ymax=0.55]
\node[anchor=center,label=south west:$O$] at (axis cs:0,0){};
\addplot[domain={-1:0}]{1/((x+1)^{3/2})};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:我已设法使用新定义的命令 vasymptote 添加渐近线。我的图表目前如下所示:
该图没有行 \addplot[domain={-1:0}]{1/((x+1)^{3/2})};
上图的代码相同,只是多了个新命令:
\newcommand{\vasymptote}[2][]{
\draw [densely dashed,#1] ({rel axis cs:0,0} -| {axis cs:#2,0}) -- ({rel axis cs:0,1} -| {axis cs:#2,0});
}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
axis line style=thick,
xmin=-1, xmax=0,
ymin=0, ymax=10,
enlarge x limits=0.15, enlarge y limits=0.15,
xtick={-1,0}, ytick=\empty,
xlabel={$x$}, ylabel={$y$},
every axis x label/.style={at={(current axis.right of origin)}, anchor=north west},
every axis y label/.style={at={(current axis.above origin)}, anchor=south east},
axis on top,
]
\node[anchor=center, label=south west:$O$] at (axis cs:0,0){};
\addplot[domain=-1:0, fill=pink, y filter/.expression={x==-1?10:y}, samples=50, smooth]{1/((x+1)^(3/2))} \closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}