如何在垂直曲线和水平线之间进行$x=1-y^2$
阴影$x=y^3-y$
处理$y=0.7$ 和 $y=-0.5$?
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{mathtools,amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{every x tick label/.append style={font=\tiny, yshift=0.5ex}}
\pgfplotsset{every y tick label/.append style={font=\tiny, xshift=0.5ex}}
\pgfplotsset{every axis plot/.append style={ thick}}
\usepgflibrary{shapes.misc}
\pgfkeys{/pgfplots/axis labels at tip/.style={
xlabel style={at={(current axis.right of origin)}, xshift=1.5ex, anchor=center},
ylabel style={at={(current axis.above origin)}, yshift=1.5ex, anchor=center}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[scale=1,
axis on top=true,
axis lines=middle,
axis line style={thick,-latex},
y=3cm,
x=3cm,
restrict y to domain=-2:2,
restrict x to domain=-0.5:1,
xmin=-1.5,xmax=1.5,
ymin=-1.5,ymax=1.5,
xlabel=$x$,
ylabel=$y$,
axis labels at tip,
xtick={-2,...,2},
ytick={-2,...,2},
]
\addplot [name path=E,very thick,DodgerBlue4,domain=-0.7:0.9,samples=200] ({1-x^2},{x});
\addplot [name path=D,very thick,Chartreuse4,domain=-0.7:0.9,samples=100] ({x^3-x},{x});
\addplot[name path=A,mark=none,gray] coordinates {(0.51,0.7) (-0.357,0.7)};
\addplot[name path=B,mark=none,gray] coordinates {(0.75,-0.5) (0.375,-0.5)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
欢迎!您可以使用密钥执行此操作soft clip={domain y=-0.5:0.7}
,
\addplot[red!20] fill between[of=E and D,soft clip={domain y=-0.5:0.7}];
完整代码:
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{mathtools,amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{every x tick label/.append style={font=\tiny, yshift=0.5ex}}
\pgfplotsset{every y tick label/.append style={font=\tiny, xshift=0.5ex}}
\pgfplotsset{every axis plot/.append style={ thick}}
\usepgflibrary{shapes.misc}
\pgfkeys{/pgfplots/axis labels at tip/.style={
xlabel style={at={(current axis.right of origin)}, xshift=1.5ex, anchor=center},
ylabel style={at={(current axis.above origin)}, yshift=1.5ex, anchor=center}}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[scale=1,
axis on top=true,
axis lines=middle,
axis line style={thick,-latex},
y=3cm,
x=3cm,
restrict y to domain=-2:2,
restrict x to domain=-0.5:1,
xmin=-1.5,xmax=1.5,
ymin=-1.5,ymax=1.5,
xlabel=$x$,
ylabel=$y$,
axis labels at tip,
xtick={-2,...,2},
ytick={-2,...,2},
]
\addplot [name path=E,very thick,DodgerBlue4,domain=-0.7:0.9,samples=200] ({1-x^2},{x});
\addplot [name path=D,very thick,Chartreuse4,domain=-0.7:0.9,samples=100] ({x^3-x},{x});
\addplot[red!20] fill between[of=E and D,soft clip={domain y=-0.5:0.7}];
\addplot[name path=A,mark=none,gray] coordinates {(0.51,0.7) (-0.357,0.7)};
\addplot[name path=B,mark=none,gray] coordinates {(0.75,-0.5) (0.375,-0.5)};
\end{axis}
\end{tikzpicture}
\end{document}