我幾乎沒有任何經驗,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}