대규모 CSV에 플롯할 범례 항목을 선택적으로 추가합니다.

대규모 CSV에 플롯할 범례 항목을 선택적으로 추가합니다.

나는 63줄의 줄거리를 갖고 있는데 그 중 일부에만 범례 항목을 추가하고 싶습니다. 전체 범례는 페이지의 절반을 차지하며 이 \ref방법을 사용하면 주변 플롯과 일관성이 제공되지 않습니다. 나는매우Jake의 자동 범례 플롯의 해킹 및 수정된 버전(https://tex.stackexchange.com/a/24023/4621) 일부 자동 색상 지정 및 신뢰 구간에 대한 일부 채워진 플롯이 포함되어 있습니다.

로 생성된 목록의 etoolbox로 이것을 시도했지만 추가된 범례 항목의 색상이 잘못되었습니다.\ifinlist\forcsvlist

어떤 아이디어가 있나요?

비트가 없으면 \ifinlist완벽하게 작동하지만 특정 줄(열/무엇이든)에 대한 범례 항목만 추가하고 싶습니다.

부분적으로 마법을 수행하는 함수는 다음과 같습니다.

\newcommand*{\plotFileRainbowCertaintyLegendList}[5]{
  \begin{tikzpicture}
    \begin{axis}[
        %Unboxed,
        %Dates,
        %twocolumn,
        y tick label style={/pgf/number format/fixed},
        xlabel={},
        legend columns = 3,
        legend style={at={(0.5,-0.1)},anchor=north},
        #4
      ]
    %By column number
    \forcsvlist{\listadd\LegendList}{50,52,53,56}
    %By column name
    %\forcsvlist{\listadd\LegendList}{col1Name,col2Name,etc...}

    \pgfplotstableread{#1}\Mod
    \pgfplotstableread{#2}\ModLow
    \pgfplotstableread{#3}\ModHigh


    \def\WaveLow{360}
    \def\WaveHigh{660}

    \pgfplotstablegetcolsof{\Mod}
    \pgfmathtruncatemacro\numberofcols{\pgfplotsretval-1}
    \pgfmathsetmacro{\waveStep}{(\WaveHigh-\WaveLow)/\numberofcols}

      \pgfplotsinvokeforeach{1,...,\numberofcols}{
        \pgfmathparse{\WaveLow+##1*\waveStep}
        \definecolor{Offence##1}{wave}{\pgfmathresult}

          \addplot+[Offence##1!50,opacity=0.01,name path=confLow, mark = none, line width = 0, forget plot,#5] table [y index=##1] \ModLow ;
          \addplot+[Offence##1!50,opacity=0.01,name path=confHigh, mark = none, line width = 0, forget plot,#5] table [y index=##1] \ModHigh ;
          \addplot[Offence##1!70,opacity=0.5, forget plot,#5] fill between[of=confLow and confHigh];

        \pgfplotstablegetcolumnnamebyindex{##1}\of{\Mod}\to{\colname}
        \addplot+[Offence##1,solid,thick,mark=none,#5] table [y index=##1] {\Mod};
        %By column number
        \xifinlist{##1}{\LegendList}{\addlegendentryexpanded{\colname};}{}
      }
        %By column name
        %\xifinlist{\colname}{\LegendList}{\addlegendentryexpanded{\colname};}{}
      %}
    \end{axis}
  \end{tikzpicture}
} 

다음과 같은 출력이 생성됩니다.

선택적 범례 항목이 없는 위 함수의 출력 예

답변1

이것은 가능합니다. 자세한 내용은 코드의 주석을 살펴보시기 바랍니다.

% used PGFPlots v1.14
%
% these are just some dummy data files
\begin{filecontents*}{low.txt}
x y1 y2 y3 y4 y5 y6 y7 y8 y9
1 13 23 33 43 53 63 73 83 93
9 13 23 33 43 53 63 73 83 93
\end{filecontents*}
\begin{filecontents*}{med.txt}
x y1 y2 y3 y4 y5 y6 y7 y8 y9
1 15 25 35 45 55 65 75 85 95
9 15 25 35 45 55 65 75 85 95
\end{filecontents*}
\begin{filecontents*}{high.txt}
x y1 y2 y3 y4 y5 y6 y7 y8 y9
1 18 28 38 48 58 68 78 88 98
9 18 28 38 48 58 68 78 88 98
\end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{
        pgfplots.fillbetween,
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            no markers,
        ]
                \pgfplotstableread{med.txt}\Mod
                \pgfplotstableread{low.txt}\ModLow
                \pgfplotstableread{high.txt}\ModHigh

                \def\WaveLow{360}
                \def\WaveHigh{660}
            \pgfplotstablegetcolsof{\Mod}
            \pgfmathtruncatemacro\numberofcols{\pgfplotsretval-1}
            \pgfmathsetmacro{\waveStep}{(\WaveHigh-\WaveLow)/\numberofcols}

%            % this was the old command ...
%            \pgfplotsinvokeforeach{1,...,\numberofcols}{
            % ... which is replaced by a list that only contains the column
            % numbers for which the legend entry should be shown
            \pgfplotsinvokeforeach{4,8}{
                    \pgfmathparse{\WaveLow+#1*\waveStep}
                    \definecolor{Offence#1}{wave}{\pgfmathresult}

                \addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confLow]
                    table [y index=#1] \ModLow;
                \addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confHigh]
                    table [y index=#1] \ModHigh;
                \addplot  [Offence#1!70,opacity=0.50,forget plot]
                    fill between [of=confLow and confHigh];

                    \pgfplotstablegetcolumnnamebyindex{#1}\of{\Mod}\to{\colname}
                \addplot+ [Offence#1,solid,thick]
                    table [y index=#1] {\Mod};
                    \addlegendentryexpanded{\colname};
            }

            % then provide a second one the previous commands but this time only
            % with the elements that should not show up in the legend
            % (I hope you get the idea of how to do it with this example)
            \pgfplotsinvokeforeach{1,...,3,5,6,...,7,\numberofcols}{
                    \pgfmathparse{\WaveLow+#1*\waveStep}
                    \definecolor{Offence#1}{wave}{\pgfmathresult}

                \addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confLow]
                    table [y index=#1] \ModLow;
                \addplot+ [Offence#1!50,opacity=0.01,forget plot,name path=confHigh]
                    table [y index=#1] \ModHigh;
                \addplot  [Offence#1!70,opacity=0.50,forget plot]
                    fill between [of=confLow and confHigh];

                    \pgfplotstablegetcolumnnamebyindex{#1}\of{\Mod}\to{\colname}
                \addplot+ [Offence#1,solid,thick]
                    table [y index=#1] {\Mod};
%                    % and of course this time don't provide the legend command
%                    \addlegendentryexpanded{\colname};
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

위 코드의 결과를 보여주는 이미지

관련 정보