我试图在两条线之间画阴影

我试图在两条线之间画阴影

这些线是由点创建的,有人能给出一些关于如何做到这一点的建议吗?谢谢!

    \documentclass{article}

    \usepackage{graphicx}
    \usepackage{siunitx}
    \usepackage{pgfplots}

    \begin{document}
    \begin{center}
    \begin{figure}
    \begin{tikzpicture}

    \begin{axis}
    [
    scale only axis,
    width=1\textwidth,
    height=8cm, 
    xlabel={Deflection (\si{in{.}})},
    ylabel={Load (\si{kips})},
    xmin=0,
    xmax=1.5,
    ymin=0,
    ymax=2,
    ytick={0,0.5,1.0,1.5,2.0},
    %ymajorgrids,
    grid=major,
    xtick pos=left,
    ytick pos=left,
    y tick label style={    /pgf/number format/fixed,
            /pgf/number format/fixed zerofill,
            /pgf/number format/precision=1},
    ]

   \addplot[mark=none, color=blue, line width=1pt] coordinates {
   (0.00000,    0)
   (0.04972, 0.112328)
   (0.10042,    0.249996)
   (0.14986,    0.378274)
   (0.20003,    0.539127)
   (0.24985,    0.741852)
   (0.30036,    1.009286)
   (0.35022,    1.311160)
   (0.40011,    1.557292)
   (0.44918,    1.738888)
   (0.46000,    1.750000)
   (0.47000,    1.760000)
   (0.50046,    1.876879)
   (0.636507,   1.863208)
   (0.701572,   1.873752)
   (0.800000,   1.88)
   (0.884833,   1.823338)
   (1.24,           1.370000)
   (1.40,           1.210000)
    };      



   \addplot[ mark=none, color=green, line width=1pt, dashed] coordinates {
   (0.00,   0)
   (0.05,   0.054535)
   (0.10,   0.116885)
   (0.15,   0.22159)
   (0.20,   0.361565)
   (0.25,   0.499317)
   (0.30,   0.703649)
   (0.35,   0.976836)
   (0.40,   1.293226)
   (0.41,   1.347)
   (0.42,   1.33)
   (0.45,   1.444132)
   (0.47,   1.537)
   (0.48,   1.56)
   (0.49,   1.55)
   (0.50,   1.55)
   (0.50,   1.576024)
   (0.511176,   1.60428)
   (0.512776    ,  1.603344)
   (0.590467,   1.534579)
   (0.839806,   1.479985)
   (1.124547,   1.247752)
    };      

    \end{axis}
    % Make axis on other side for metric description
    \begin{axis}[
    scale only axis,
    width=1\textwidth,
    height=8cm, 
    xmin=0,
    xmax=38.1,
    ymin=0,
    ymax=8.896,
    axis y line*=right,
    axis x line*=top,
    ylabel near ticks,
    ylabel={Load (\si{\kilo\newton})},
    xlabel near ticks,
    xlabel={Deflection (\si{\milli\meter})},
    %major grid style={dashed,red},
    %grid=major,
       y tick label style={
            /pgf/number format/fixed,
            /pgf/number format/fixed zerofill,
            /pgf/number format/precision=1}
     ]
    \end{axis}

    \end{tikzpicture}
    \caption{Load deflection curve for GFRP}
    \end{figure}
    \end{center}

答案1

您可以使用fillbetween以下库pgfplots

   \addplot fill between[of=A and B,split,every segment no 1/.style=
               {left color=orange, right color=blue},soft clip={domain=0:1.124547}];    
      %% Remove soft clip={domain=0:1.124547} if you want

代码:

    \documentclass{article}

    \usepackage{graphicx}
    \usepackage{siunitx}
    \usepackage{pgfplots}
    \usepgfplotslibrary{fillbetween}      %% you need this
    \pgfplotsset{compat=1.10}

    \begin{document}
    \begin{center}
    \begin{figure}
    \begin{tikzpicture}

    \begin{axis}
    [
    scale only axis,
    width=1\textwidth,
    height=8cm,
    xlabel={Deflection (\si{in{.}})},
    ylabel={Load (\si{kips})},
    xmin=0,
    xmax=1.5,
    ymin=0,
    ymax=2,
    ytick={0,0.5,1.0,1.5,2.0},
    %ymajorgrids,
    grid=major,
    xtick pos=left,
    ytick pos=left,
    y tick label style={    /pgf/number format/fixed,
            /pgf/number format/fixed zerofill,
            /pgf/number format/precision=1},
    ]

   \addplot[name path=A,mark=none, color=blue, line width=1pt] coordinates {
   (0.00000,    0)
   (0.04972, 0.112328)
   (0.10042,    0.249996)
   (0.14986,    0.378274)
   (0.20003,    0.539127)
   (0.24985,    0.741852)
   (0.30036,    1.009286)
   (0.35022,    1.311160)
   (0.40011,    1.557292)
   (0.44918,    1.738888)
   (0.46000,    1.750000)
   (0.47000,    1.760000)
   (0.50046,    1.876879)
   (0.636507,   1.863208)
   (0.701572,   1.873752)
   (0.800000,   1.88)
   (0.884833,   1.823338)
   (1.24,           1.370000)
   (1.40,           1.210000)
    };



   \addplot[name path=B, mark=none, color=green, line width=1pt, dashed] coordinates {
   (0.00,   0)
   (0.05,   0.054535)
   (0.10,   0.116885)
   (0.15,   0.22159)
   (0.20,   0.361565)
   (0.25,   0.499317)
   (0.30,   0.703649)
   (0.35,   0.976836)
   (0.40,   1.293226)
   (0.41,   1.347)
   (0.42,   1.33)
   (0.45,   1.444132)
   (0.47,   1.537)
   (0.48,   1.56)
   (0.49,   1.55)
   (0.50,   1.55)
   (0.50,   1.576024)
   (0.511176,   1.60428)
   (0.512776    ,  1.603344)
   (0.590467,   1.534579)
   (0.839806,   1.479985)
   (1.124547,   1.247752)
    };
   \addplot fill between[of=A and B,split,every segment no 1/.style=
{left color=orange, right color=blue},soft clip={domain=0:1.124547}];    %% Remove soft clip={domain=0:1.124547} if you want
    \end{axis}
    % Make axis on other side for metric description
    \begin{axis}[
    scale only axis,
    width=1\textwidth,
    height=8cm,
    xmin=0,
    xmax=38.1,
    ymin=0,
    ymax=8.896,
    axis y line*=right,
    axis x line*=top,
    ylabel near ticks,
    ylabel={Load (\si{\kilo\newton})},
    xlabel near ticks,
    xlabel={Deflection (\si{\milli\meter})},
    %major grid style={dashed,red},
    %grid=major,
       y tick label style={
            /pgf/number format/fixed,
            /pgf/number format/fixed zerofill,
            /pgf/number format/precision=1}
     ]
    \end{axis}

    \end{tikzpicture}
    \caption{Load deflection curve for GFRP}
    \end{figure}
    \end{center}
   \end{document}

在此处输入图片描述

如果没有soft clip={domain=0:1.124547}我们

在此处输入图片描述

相关内容