填充由三点界定的区域

填充由三点界定的区域

梅威瑟:

\documentclass[12pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usepgfplotslibrary{fillbetween}
\pagestyle{empty}
\begin{document}
\definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
\definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
\definecolor{sexdts}{rgb}{0.1803921568627451,0.49019607843137253,0.19607843137254902}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
axis line style={stealth-stealth},
xmin=-6,
xmax=6,
ymin=-6,
ymax=6,
xtick={-5,...,5},
ytick={-5,-4,...,5},]
\draw [samples=50,rotate around={0:(0,0)},xshift=0cm,yshift=0cm,line width=0.8pt,color=sexdts,domain=-4:4,<->,name path=C1] plot (\x,{(\x)^2/2/2});
\draw [line width=0.5pt,color=rvwvcq,<->,name path=C2] (2,-3.) -- (2,5.);
\begin{scriptsize}
\draw [fill=black] (0,0) circle (1.8pt);
\draw[color=black] (0.30,-0.30) node [rotate=00]{O};
\draw [fill=black] (2,1) circle (1.8pt);
\draw[color=black] (2.40,0.8) node {B};
\draw [fill=black] (2,0) circle (1.8pt);
\draw[color=black] (2.30,-0.40) node [rotate=00]{A};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}

问题:如何填充由三个坐标覆盖的区域O(0,0)A(2,0)B(2,1)使用具有不同不透明度的不同颜色?

答案1

不同颜色具有不同不透明度是什么意思?只有一种颜色,我们就可以得到这个。

\documentclass[12pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usepgfplotslibrary{fillbetween}
\pagestyle{empty}
\begin{document}
\definecolor{wrwrwr}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
\definecolor{rvwvcq}{rgb}{0.08235294117647059,0.396078431372549,0.7529411764705882}
\definecolor{sexdts}{rgb}{0.1803921568627451,0.49019607843137253,0.19607843137254902}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
axis line style={stealth-stealth},
xmin=-6,
xmax=6,
ymin=-6,
ymax=6,
xtick={-5,...,5},
ytick={-5,-4,...,5},]
\draw [samples=50,rotate around={0:(0,0)},xshift=0cm,yshift=0cm,line width=0.8pt,color=sexdts,domain=-4:4,<->,name path=C1] plot (\x,{(\x)^2/2/2});
\draw [line width=0.5pt,color=rvwvcq,<->,name path=C2] (2,-3.) -- (2,5.);
\begin{scriptsize}
\draw [fill=black] (0,0) circle (1.8pt);
\draw[color=black] (0.30,-0.30) node [rotate=00]{O};
\draw [fill=black] (2,1) circle (1.8pt);
\draw[color=black] (2.40,0.8) node {B};
\draw [fill=black] (2,0) circle (1.8pt);
\draw[color=black] (2.30,-0.40) node [rotate=00]{A};

\path [name path=B]
(\pgfkeysvalueof{/pgfplots/xmin},0) --
(\pgfkeysvalueof{/pgfplots/xmax},0);
\addplot[orange,opacity=.5] fill between [
of=C1 and B,
soft clip={domain=0:2},
];
\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}

充满

相关内容