如何改进(添加阴影)

如何改进(添加阴影)
\documentclass[12pt,a4paper,openany]{book}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{amsmath,amssymb,amsthm}
%%%%%%%%%%%%%%%%%%%
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns,shapes.geometric}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm]
\begin{axis}[unbounded coords=jump,
x=1cm,y=1cm,
axis lines=middle,
xmin=-8,
xmax=8,
ymin=-5,
ymax=5,
ytick=\empty,
xtick=\empty]
\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1,name
path=left] {(1/x)} node[pos=0.1,below=40mm]{$(A_3)$}node[pos=0.1,below=20mm,right=40mm]{$(\mathcal{C}_1)$};
\addplot[line width=2pt,color=blue,smooth,samples=51,domain=0.1:8,name
path=right] {(1/x)} node[pos=0.95,above=20mm]{$(A_1)$}node[pos=0.95,above=20mm,left=50mm]{$(\mathcal{C}_1)$};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=0.1:8,name
path=right] {-(1/x)} node[pos=0.95,below=40mm]{$(A_4)$}node[pos=0.95,below=20mm,left=50mm]{$(\mathcal{C}_2) $};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=-8:-0.1,name
path=left] {-(1/x)} node[pos=0.1,above=30mm]{$(A_4)$}node[pos=0.1,above=20mm,right=40mm]{$(\mathcal{C}_2) $};
\end{axis}
\end{tikzpicture}
\end{document}

我想获得这样的东西

在此处输入图片描述

答案1

对于孵化,我没有使用图案,因为它很难定制。在这次尝试中,我使用了:

  • 旋转网格来创建阴影(您可以通过更改参数来调整平行线之间的距离ystep
  • \clip指定填充区域

相应的代码如下:

\documentclass[12pt,a4paper,openany]{book}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{amsmath,amssymb,amsthm}   

\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm]
\begin{axis}[unbounded coords=jump,
  x=1cm,y=1cm,
  axis lines=middle,
  xmin=-8,
  xmax=8,
  ymin=-5,
  ymax=5,
  ytick=\empty,
  xtick=\empty,
  axis on top]

% A3 hatch
\begin{scope}
  \clip plot[samples=51,domain=-8:-0.1] (\x, {1/\x}) -| (-8,-1/8) --cycle;
  \draw[blue!20,xstep=0cm,ystep=0.5cm,rotate=45] (-15,-15) grid (15,15);
\end{scope}

% A1 hatch
\begin{scope}
  \clip plot[samples=51,domain=0.1:8] (\x, {1/\x}) |- (0.1,1/0.1) --cycle;
  \draw[blue!20,xstep=0cm,ystep=0.5cm,rotate=45] (-15,-15) grid (15,15);
\end{scope}

% A4 hatch
\begin{scope}
  \clip plot[samples=51,domain=-8:-0.1] (\x, {-1/\x}) -| (-8,1/8) --cycle;
  \draw[red!20,xstep=0cm,ystep=0.5cm,rotate=-45] (-25,-25) grid (15,15);
\end{scope}

% A2 hatch
\begin{scope}
  \clip plot[samples=51,domain=0.1:8] (\x, {-1/\x}) |- (0.1,-1/0.1) --cycle;
  \draw[red!20,xstep=0cm,ystep=0.5cm,rotate=-45] (-25,-25) grid (15,15);
\end{scope}

% Fill between 
\begin{scope}
  \fill[yellow!10,opacity=] plot[samples=51,domain=0.1:8] (\x, {-1/\x}) -- plot[samples=51,domain=8:0.1] (\x, {1/\x}) -- plot[samples=51,domain=-0.1:-8] (\x, {-1/\x}) -- plot[samples=51,domain=-8:-0.1] (\x, {1/\x}) -- cycle ; 
\end{scope}


% Your code (I removed path names)
\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1] {(1/x)};

\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1] {(1/x)} node[pos=0.1,below=40mm]{$(A_3)$}node[pos=0.1,below=20mm,right=40mm]{$(\mathcal{C}_1)$};

\addplot[line width=2pt,color=blue,smooth,samples=51,domain=0.1:8] {(1/x)} node[pos=0.95,above=20mm]{$(A_1)$}node[pos=0.95,above=20mm,left=50mm]{$(\mathcal{C}_1)$};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=0.1:8] {-(1/x)} node[pos=0.95,below=40mm]{$(A_4)$}node[pos=0.95,below=20mm,left=50mm]{$(\mathcal{C}_2) $};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=-8:-0.1] {-(1/x)} node[pos=0.1,above=30mm]{$(A_4)$}node[pos=0.1,above=20mm,right=40mm]{$(\mathcal{C}_2) $};
\end{axis}
\end{tikzpicture}
\end{document}

产量:

在此处输入图片描述

对于中间区域的阴影,以下是相应的代码:

\documentclass[12pt,a4paper,openany]{book}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{amsmath,amssymb,amsthm}
%%%%%%%%%%%%%%%%%%%


\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm]
\begin{axis}[unbounded coords=jump,
  x=1cm,y=1cm,
  axis lines=middle,
  xmin=-8,
  xmax=8,
  ymin=-5,
  ymax=5,
  ytick=\empty,
  xtick=\empty,
  axis on top]

% A3 hatch
\begin{scope}
  \clip plot[samples=51,domain=-8:-0.1] (\x, {1/\x}) -| (-8,-1/8) --cycle;
  \draw[blue!20,xstep=0cm,ystep=0.5cm,rotate=45] (-15,-15) grid (15,15);
\end{scope}

% A1 hatch
\begin{scope}
  \clip plot[samples=51,domain=0.1:8] (\x, {1/\x}) |- (0.1,1/0.1) --cycle;
  \draw[blue!20,xstep=0cm,ystep=0.5cm,rotate=45] (-15,-15) grid (15,15);
\end{scope}

% A4 hatch
\begin{scope}
  \clip plot[samples=51,domain=-8:-0.1] (\x, {-1/\x}) -| (-8,1/8) --cycle;
  \draw[red!20,xstep=0cm,ystep=0.5cm,rotate=-45] (-25,-25) grid (15,15);
\end{scope}

% A2 hatch
\begin{scope}
  \clip plot[samples=51,domain=0.1:8] (\x, {-1/\x}) |- (0.1,-1/0.1) --cycle;
  \draw[red!20,xstep=0cm,ystep=0.5cm,rotate=-45] (-25,-25) grid (15,15);
\end{scope}

% Fill between 
\begin{scope}
  \clip plot[samples=51,domain=0.1:8] (\x, {-1/\x}) -- plot[samples=51,domain=8:0.1] (\x, {1/\x}) -- plot[samples=51,domain=-0.1:-8] (\x, {-1/\x}) -- plot[samples=51,domain=-8:-0.1] (\x, {1/\x}) -- cycle ; 

  \draw[orange!40,xstep=0cm,ystep=0.5cm,rotate=-45] (-25,-25) grid (15,15);
  \draw[orange!40,xstep=0cm,ystep=0.5cm,rotate=45] (-25,-25) grid (15,15);
  \node[above right] at (0,0){$(A_5)$};

\end{scope}



\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1] {(1/x)};

\addplot[line width=2pt,color=blue,smooth,samples=51,domain=-8:-0.1] {(1/x)} node[pos=0.1,below=40mm]{$(A_3)$}node[pos=0.1,below=20mm,right=40mm]{$(\mathcal{C}_1)$};

\addplot[line width=2pt,color=blue,smooth,samples=51,domain=0.1:8] {(1/x)} node[pos=0.95,above=20mm]{$(A_1)$}node[pos=0.95,above=20mm,left=50mm]{$(\mathcal{C}_1)$};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=0.1:8] {-(1/x)} node[pos=0.95,below=40mm]{$(A_4)$}node[pos=0.95,below=20mm,left=50mm]{$(\mathcal{C}_2) $};
\addplot[line width=2pt,color=red,smooth,samples=51,domain=-8:-0.1] {-(1/x)} node[pos=0.1,above=30mm]{$(A_4)$}node[pos=0.1,above=20mm,right=40mm]{$(\mathcal{C}_2) $};
\end{axis}
\end{tikzpicture}
\end{document}

得出的结果是:

在此处输入图片描述

在这种情况下,我添加了两个旋转的网格。

答案2

在这里编译:阿希希·多玉

import graph;
import patterns;
usepackage("amsmath");

// The default unit and linewidth
unitsize(1cm);
size(8cm,false);
defaultpen(linewidth(1bp));

// Definition of the graphs
real F(real x){return 1/x;}
real G(real x){return -1/x;}
path f1=graph(F,-8,-0.2,350),f2=graph(F,0.2,8,350),
        g1=graph(G,-8,-0.2,350),g2=graph(G,0.2,8,350);

// Draw patterns
picture pic1, pic2;
add("hatch1",hatch(NE));
fill(pic1,box((-8,F(-0.2)),(8,F(0.2))),pattern("hatch1"));
clip(pic1,f1--(-8,F(-0.2))--cycle^^f2--(8,F(0.2))--cycle);
add(pic1);

add("hatch2",hatch(SE));
fill(pic2,box((-8,F(-0.2)),(8,F(0.2))),pattern("hatch2"));
clip(pic2,g1--(-8,F(0.2))--cycle^^g2--(8,F(-0.2))--cycle);
add(pic2);

pic2=new picture;
fill(pic2,box((-8,F(-0.2)),(8,F(0.2))),cyan);
path AhihidoNgoc=f1--g2--reverse(f2)--reverse(g1)--cycle;
clip(pic2,AhihidoNgoc);
add(pic2);

// Draw two graphs
draw(f1^^f2,blue);
draw(g1^^g2,red);

// Draw Xaxis and Yaxis
path Xaxis=(-8,0)--(8,0),Yaxis=(0,F(0.2))--(0,F(-0.2));
draw(Xaxis,Arrow(1bp,arrowhead=TeXHead));
draw(Yaxis,BeginArrow(1bp,arrowhead=TeXHead));

// Add labels
label(Label("$(\mathcal{C}_1)$",Relative(0.6),UnFill),f1,blue);
label(Label("$(\mathcal{C}_1)$",Relative(0.4),LeftSide,UnFill),f2,blue);
label(Label("$(\mathcal{C}_2)$",Relative(0.6),LeftSide,UnFill),g1,red);
label(Label("$(\mathcal{C}_2)$",Relative(0.4),UnFill),g2,red);

label(Label("$(A_1)$",UnFill),(7,G(-0.25)),blue);
label(Label("$(A_2)$",UnFill),(-7,G(-0.25)),red);
label(Label("$(A_3)$",UnFill),(-7,G(0.25)),blue);
label(Label("$(A_4)$",UnFill),(7,G(0.25)),red);

frame f;
label(f,Label("$(A_5)$"),0,Fill(white));
add(rotate(45)*f);

在此处输入图片描述

相关内容