我几乎没有任何经验,pgfplot
而且我在一些看起来很简单的事情上遇到了一些问题。
我想要做的是填充一个函数和两条垂直线之间的区域,该区域由一条水平线与该函数的交点标识。
我找到了交叉点,并且可以正确地绘制垂直线,但我不明白如何填充该区域
以下是我迄今为止设法生成的代码。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[scale=1]
\addplot+[name path global=GraphCurve, domain=0.5:1.5, samples=400, color=black, mark=none]{0.09*x^2/sqrt((1-x^2)^2+(0.09*x)^2)};
\addplot+[name path global=HorizontalLine, domain=0.5:1.5,mark=none, opacity=0]{0.5};
\path[dashed,name intersections={of=GraphCurve and HorizontalLine,name=i}] (i-2)%
\pgfextra{\pgfgetlastxy{\macrox}{\macroy}%
\global\let\macrox\macrox};
\def \xinta {\macrox}
\draw[name path global=vert1, dashed](i-2) -- (\xinta,0);
\path (i-1)
\pgfextra{\pgfgetlastxy{\macrox}{\macroy}%
\global\let\macrox\macrox};
\def \xintb {\macrox}
\draw[name path global=vert2,dashed](i-1) -- (\xintb,0);
\coordinate [label=left:$A$](A) at (i-1);
\coordinate [label=right:$B$](B) at (i-2);
\end{axis}
\end{tikzpicture}
\caption{This picture has been created with Pgfplots}
\end{figure}
\end{document}
有人可以帮忙吗?
答案1
我会剪辑它。
代码
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usetikzlibrary{calc,intersections,backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[name path global=GraphCurve, domain=0.5:1.5, samples=400, color=black, mark=none]{0.09*x^2/sqrt((1-x^2)^2+(0.09*x)^2)};
\addplot+[name path global=HorizontalLine, domain=0.5:1.5,mark=none, opacity=0]{0.5};
\path [name intersections={of=GraphCurve and HorizontalLine,name=i}];
\draw[dashed] (i-1) coordinate[label=left:$A$] -- ({axis cs:0,0} -| i-1);
\draw[dashed] (i-2) coordinate[label=right:$B$] -- ({axis cs:0,0} -| i-2);
\begin{scope}[on background layer]
\clip ({axis cs:0,0} -| i-1) rectangle ({axis cs:0,\pgfkeysvalueof{/pgfplots/ymax}} -| i-2);
\addplot+ [domain=0.5:1.5, samples=400, draw=none, mark=none, fill=gray] {0.09*x^2/sqrt((1-x^2)^2+(0.09*x)^2)} \closedcycle;
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}