Pgfplot。降低 RGB 颜色的强度

Pgfplot。降低 RGB 颜色的强度

在此处输入图片描述

我想降低图表中填充的强度。但是,!10在填充部分中指定 RGB 颜色后会导致错误。我确实需要使用 RGB 颜色,以与其他图表保持一致,因此我不能只使用fill=blue!10。如果有重复,请指出,我会删除此问题。我找不到与我的问题类似的内容。

我的代码:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{biblatex}
\usepackage{subfigure}
\addbibresource{biblatex-examples.bib}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{filecontents}

\begin{document}

\begin{filecontents}{datax.dat}
x,y
-2,0
-1.925,0.001
-1.85,0
-1.775,0.001
-1.7,0.001
-1.625,0.001
-1.55,0
-1.475,0
-1.4,0.004
-1.325,0.004
-1.25,0.003
-1.175,0.006
-1.1,0.01
-1.025,0.008
-0.95,0.02
-0.875,0.025
-0.8,0.027
-0.725,0.044
-0.65,0.067
-0.575,0.106
-0.5,0.145
-0.425,0.276
-0.35,0.417
-0.275,0.595
-0.2,0.832
-0.125,1.183
-0.05,1.576
0.0249999999999999,2.014
0.1,1.747
0.175,1.412
0.25,1.029
0.325,0.877
0.4,0.563
0.475,0.435
0.55,0.279
0.625,0.194
0.7,0.126
0.775,0.085
0.85,0.051
0.925,0.035
1,0.025
1.075,0.016
1.15,0.016
1.225,0.006
1.3,0.013
1.375,0.014
1.45,0.007
1.525,0.003
1.6,0.003
1.675,0.002
1.75,0.001
1.825,0.002
1.9,0.001
1.975,0.002
2.05,0.001
\end{filecontents}


\usetikzlibrary{datavisualization}


    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        /pgf/declare function={
            xmin=-2;
            xmax=2;
        },
    }

\begin{tikzpicture}
    \begin{axis}[
        minor tick num =1,
        grid=both,
        domain=0:2,
        axis lines=left,
        axis background/.style={fill=gray!10},
        axis line style={->},
        x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
        y label style={at={(axis description cs:-0.1,.5)},anchor=south},
        ylabel= density,
        xlabel= differences in absolute percentage errors,
        axis on top,
        xmin=xmin,
        xmax=xmax,
        ymin=-0.017,
        domain=xmin:xmax
    ]
        \path[name path=axis] (axis cs:xmin,0) -- (axis cs:xmax,0);
        \addplot[name path=table] table [ x index=0, y index=1, col sep=comma, ] {datax.dat};
        \addplot [fill={rgb:red,0;green,47;blue,135}]
        fill between [of=axis and table];
    \end{axis}
\end{tikzpicture}


\end{document}

答案1

您应该为此定义一种颜色。我使用myblue作为颜色名称。现在您可以myblue!50myblue!10往常一样使用。

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{biblatex}
\usepackage{subfigure}
\addbibresource{biblatex-examples.bib}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{filecontents}
\definecolor{myblue}{RGB}{0,47,135}
\begin{document}

\begin{filecontents}{datax.dat}
x,y
-2,0
-1.925,0.001
-1.85,0
-1.775,0.001
-1.7,0.001
-1.625,0.001
-1.55,0
-1.475,0
-1.4,0.004
-1.325,0.004
-1.25,0.003
-1.175,0.006
-1.1,0.01
-1.025,0.008
-0.95,0.02
-0.875,0.025
-0.8,0.027
-0.725,0.044
-0.65,0.067
-0.575,0.106
-0.5,0.145
-0.425,0.276
-0.35,0.417
-0.275,0.595
-0.2,0.832
-0.125,1.183
-0.05,1.576
0.0249999999999999,2.014
0.1,1.747
0.175,1.412
0.25,1.029
0.325,0.877
0.4,0.563
0.475,0.435
0.55,0.279
0.625,0.194
0.7,0.126
0.775,0.085
0.85,0.051
0.925,0.035
1,0.025
1.075,0.016
1.15,0.016
1.225,0.006
1.3,0.013
1.375,0.014
1.45,0.007
1.525,0.003
1.6,0.003
1.675,0.002
1.75,0.001
1.825,0.002
1.9,0.001
1.975,0.002
2.05,0.001
\end{filecontents}


\usetikzlibrary{datavisualization}


    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        /pgf/declare function={
            xmin=-2;
            xmax=2;
        },
    }

\begin{tikzpicture}
    \begin{axis}[
        minor tick num =1,
        grid=both,
        domain=0:2,
        axis lines=left,
        axis background/.style={fill=gray!10},
        axis line style={->},
        x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
        y label style={at={(axis description cs:-0.1,.5)},anchor=south},
        ylabel= density,
        xlabel= differences in absolute percentage errors,
        axis on top,
        xmin=xmin,
        xmax=xmax,
        ymin=-0.017,
        domain=xmin:xmax
    ]
        \path[name path=axis] (axis cs:xmin,0) -- (axis cs:xmax,0);
        \addplot[name path=table] table [ x index=0, y index=1, col sep=comma, ] {datax.dat};
        \addplot [fill=myblue!50]
        fill between [of=axis and table];
    \end{axis}
\end{tikzpicture}


\end{document}

在此处输入图片描述

答案2

您在寻找吗opacity

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{filecontents}

\begin{document}

\begin{filecontents}{datax.dat}
x,y
-2,0
-1.925,0.001
-1.85,0
-1.775,0.001
-1.7,0.001
-1.625,0.001
-1.55,0
-1.475,0
-1.4,0.004
-1.325,0.004
-1.25,0.003
-1.175,0.006
-1.1,0.01
-1.025,0.008
-0.95,0.02
-0.875,0.025
-0.8,0.027
-0.725,0.044
-0.65,0.067
-0.575,0.106
-0.5,0.145
-0.425,0.276
-0.35,0.417
-0.275,0.595
-0.2,0.832
-0.125,1.183
-0.05,1.576
0.0249999999999999,2.014
0.1,1.747
0.175,1.412
0.25,1.029
0.325,0.877
0.4,0.563
0.475,0.435
0.55,0.279
0.625,0.194
0.7,0.126
0.775,0.085
0.85,0.051
0.925,0.035
1,0.025
1.075,0.016
1.15,0.016
1.225,0.006
1.3,0.013
1.375,0.014
1.45,0.007
1.525,0.003
1.6,0.003
1.675,0.002
1.75,0.001
1.825,0.002
1.9,0.001
1.975,0.002
2.05,0.001
\end{filecontents}


\usetikzlibrary{datavisualization}


    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        /pgf/declare function={
            xmin=-2;
            xmax=2;
        },
    }

\begin{tikzpicture}
    \begin{axis}[
        minor tick num =1,
        grid=both,
        domain=0:2,
        axis lines=left,
        axis background/.style={fill=gray!10},
        axis line style={->},
        x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
        y label style={at={(axis description cs:-0.1,.5)},anchor=south},
        ylabel= density,
        xlabel= differences in absolute percentage errors,
        axis on top,
        xmin=xmin,
        xmax=xmax,
        ymin=-0.017,
        domain=xmin:xmax
    ]
        \path[name path=axis] (axis cs:xmin,0) -- (axis cs:xmax,0);
        \addplot[name path=table] table [ x index=0, y index=1, col sep=comma, ] {datax.dat};
        \addplot [fill={rgb:red,0;green,47;blue,135},opacity=0.2]
        fill between [of=axis and table];
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容