Agregue selectivamente entradas de leyenda para trazar en CSV grande

Agregue selectivamente entradas de leyenda para trazar en CSV grande

Tengo una trama con 63 líneas, solo para algunas de las cuales me gustaría tener entradas de leyenda. La leyenda completa ocupa media página y el uso del \refmétodo no me da coherencia con las tramas circundantes. estoy usando unmuyVersión pirateada y modificada de la trama de leyenda automática de Jake (https://tex.stackexchange.com/a/24023/4621) con algo de coloración automática y algunos gráficos rellenos para el intervalo de confianza.

Probé esto con etoolboxde \ifinlistuna lista creada con \forcsvlist, pero las entradas de leyenda que se agregan tienen el color incorrecto.

¿Algunas ideas?

Sin los \ifinlistbits funciona perfectamente, pero solo quiero agregar entradas de leyenda para ciertas líneas (columnas/lo que sea).

Aquí está la función que hace parcialmente la magia:

\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}
} 

Lo que produce resultados como:

Ejemplo de salida de la función anterior, sin entradas de leyenda selectivas

Respuesta1

Esto puede hacerse. Para más detalles, eche un vistazo a los comentarios en el código.

% 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}

imagen que muestra el resultado del código anterior

información relacionada