颜色点按照颜色图的顺序从 .csv 中散布

颜色点按照颜色图的顺序从 .csv 中散布

我想将 .csv 中的这 10 个点的颜色设置为与相应颜色图相同的颜色,按照它们出现的顺序(即完全独立于它们的 x,y 值)。我该如何实现?提前致谢!

梅威瑟:

\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.18}
\usepackage{csvsimple}

% Define inferno colormap
\pgfplotsset{%
    colormap={inferno}{%
        rgb255=(0, 0, 4)
        rgb255=(12, 8, 38)
        rgb255=(36, 12, 79)
        rgb255=(66, 10, 104)
        rgb255=(93, 18, 110)
        rgb255=(120, 28, 109)
        rgb255=(147, 38, 103)
        rgb255=(174, 48, 92)
        rgb255=(199, 62, 76)
        rgb255=(221, 81, 58)
        rgb255=(237, 105, 37)
        rgb255=(248, 133, 15)
        rgb255=(252, 165, 10)
        rgb255=(250, 198, 45)
        rgb255=(242, 230, 97)
        rgb255=(252, 255, 164)
    }
}
    
\begin{document}

% Create CSV file
\begin{filecontents*}{data.csv}
z_1_real;z_1_imag
-3.0;0
-2.7;0
-2.4;0
-2.0;0
-1.8;0
-1.5;0
-1.2;0
-1.0;0
-0.6;0
-0.3;0
\end{filecontents*}

\begin{tikzpicture}
    \begin{axis} [
        width=60mm,
        xmin=-3.5,
        xmax=0.5,
        ymin=-0.5,
        ymax=0.5,
        colorbar horizontal,
        colormap name=inferno,
        colorbar sampled,
        colormap access=piecewise const,
        point meta min=0,
        point meta max=10,
        colorbar style={
            samples=11,
            xtick={0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
            xticklabels={1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
            height=2mm,
            xtick align=outside,
            xtick pos=right,
            x tick label style={
                above,
                yshift=5mm,
                },
            x label style={
                above,
                yshift=9mm,
                },
            tick label style={above},
            tick style={
                color=black
            },
            at={(0,0.55)},
            anchor=current axis.north west
            }
        ] 
        \draw[draw=gray] (0,0) circle (1);
        \addplot[scatter, mark=*, only marks, mark options={scale=1, line width=1.5pt}] table [x=z_1_real, y=z_1_imag, col sep=semicolon] {data.csv};
    \end{axis}
\end{tikzpicture}
    
\end{document}

结果:

scatter_cmap

通缉:

期望

答案1

使用点meta=explicit symbolic

在此处输入图片描述

\documentclass{standalone}

\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.18}

% Define inferno colormap
\pgfplotsset{%
    colormap={inferno}{%
        rgb255=(0, 0, 4)
        rgb255=(12, 8, 38)
        rgb255=(36, 12, 79)
        rgb255=(66, 10, 104)
        rgb255=(93, 18, 110)
        rgb255=(120, 28, 109)
        rgb255=(147, 38, 103)
        rgb255=(174, 48, 92)
        rgb255=(199, 62, 76)
        rgb255=(221, 81, 58)
        rgb255=(237, 105, 37)
        rgb255=(248, 133, 15)
        rgb255=(252, 165, 10)
        rgb255=(250, 198, 45)
        rgb255=(242, 230, 97)
        rgb255=(252, 255, 164)
    }
}

\begin{document}

% Create CSV file
\begin{filecontents*}{data.csv}
z_1_real;z_1_imag;meta  % added column 'meta' for the order of colors
-3.0;0;0
-2.7;0;1
-2.4;0;2
-2.0;0;3
-1.8;0;4
-1.5;0;5
-1.2;0;6
-1.0;0;7
-0.6;0;8
-0.3;0;9
\end{filecontents*}

\begin{tikzpicture}
    \begin{axis} [
        width=60mm,
        xmin=-3.5,
        xmax=0.5,
        ymin=-0.5,
        ymax=0.5,
        colorbar horizontal,
        colormap name=inferno,
        colorbar sampled,
        colormap access=piecewise const,
        point meta min=0,  %<= first point
        point meta max=9,  %<= Last point
        colorbar style={
            samples=10,  %<=number of points
            xtick={0, 1, ..., 9},  %<=meta values'
            xticklabels={1, 2, ..., 10},  %<=Poitn order
            height=2mm,
            xtick align=outside,
            xtick pos=right,
            x tick label style={
                above,
                yshift=5mm,
                },
            tick label style={above},
            tick style={
                color=black
            },
            at={(0,0.55)},
            anchor=current axis.north west
            }
        ] 
        \draw[draw=gray] (0,0) circle (1);
        \addplot[scatter, mark=*, only marks, mark options={scale=1, line width=1.5pt}, scatter src=explicit, point meta=\thisrow{meta}] table [x=z_1_real, y=z_1_imag, meta=meta, col sep=semicolon] {data.csv};  %<= use of point meta here
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容