根据值添加绘图颜色

根据值添加绘图颜色

我想为 addplot 指定一个颜色范围。这是我的示例:

\documentclass[tikz]{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[xmin=0.0, xmax = 1.0, ymin=-0.0003, ymax=0.3, width=7.8cm, label={Normalized Vector Magnitude}, ylabel={Density}]
 \addplot[color=red] %here should be a range instead 
  coordinates{
  (0.0, 0.1)
  (0.1, 0.2)
  (0.2, 0.3)
  (0.3, 0.2)
  (0.4, 0.1)
  (0.5, 0.15)
  (0.6, 0.2)
  (0.7, 0.22)
  (0.8, 0.23)
  (0.9, 0.2)
  (1.0, 0.0)
 };
\end{axis}
\end{tikzpicture}
\end{document}

所以我想将 x 值范围映射到颜色范围,例如来自的色调值hsv 模型。颜色应该在这个范围内不断变化。有可能吗?

答案1

在阅读了评论的帮助手册后,我找到了适合我需要的解决方案:

\documentclass[tikz]{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\pgfplotsset{
 colormap={blackwhite}{[5pt]
    rgb255(0pt)=(255, 0, 0);
    rgb255(500pt)=(255, 255, 0);
    rgb255(500pt)=(255, 255, 0);
    rgb255(1000pt)=(0, 255, 0 );
    rgb255(1000pt)=(0, 255, 0 );
    rgb255(1500pt)=(0, 0, 255);
    rgb255(1500pt)=(0, 0, 255);
    rgb255(2000pt)=(255, 0, 255);
    rgb255(2000pt)=(255, 0, 255);
    rgb255(2500pt)=(255,0,0)
 },
}
\begin{tikzpicture}
 \begin{axis}[xmin=0.0, xmax = 1.0, ymin=-0.0003, ymax=0.3, width=7.8cm, label={Normalized Vector Magnitude}, ylabel={Density}]
 \addplot[mesh, point meta=explicit] %here should be a range instead 
  coordinates{
  (0.0, 0.1) [0]
  (0.1, 0.2) [1]
  (0.2, 0.3) [2]
  (0.3, 0.2) [3]
  (0.4, 0.1) [4]
  (0.5, 0.15) [5]
  (0.6, 0.2) [6]
  (0.7, 0.22) [7]
  (0.8, 0.23) [8]
  (0.9, 0.2) [9]
  (1.0, 0.0) [10]
 };
\end{axis}
\end{tikzpicture}
\end{document}

相关内容