편집하다

편집하다

동일한 스타일을 가진 N개의 연속 플롯 그룹을 원하는 곳에 플롯할 데이터 세트가 있습니다. 내가 고려한 옵션:

다음은 3개의 플롯으로 구성된 두 그룹이 있는 예입니다. 이 마지막 방법을 사용하여 원하는 작업을 수행합니다.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
            \begin{axis}[
            ]
                    % First group of identical plots
                    \addplot+ [domain=-1:2, samples=10] {1*x+1};
                    \pgfplotsset{cycle list shift=-1}
                    \addplot+ [domain=-1:2, samples=10] {1*x+2};
                    \pgfplotsset{cycle list shift=-2}
                    \addplot+ [domain=-1:2, samples=10] {1*x+3};
                    % Second group of identical plots
                    \addplot+ [domain=-1:2, samples=10] {2*x+1};
                    \pgfplotsset{cycle list shift=-3}
                    \addplot+ [domain=-1:2, samples=10] {2*x+2};
                    \pgfplotsset{cycle list shift=-4}
                    \addplot+ [domain=-1:2, samples=10] {2*x+3};
                    % and so on... I have a dozen of sets of 5 plots. It would get tedious.
            \end{axis}
    \end{tikzpicture}
\end{document}

세 개의 플롯으로 구성된 두 그룹

나는 다음과 같은 구문을 사용하여 더 깨끗하고 자동화된 것을 원합니다.

cycle multi list={%
        color list\nextlist
        [5 of]mark list
}

하지만 어떻게 해야 할지 모르겠어요!

편집: 모든 N 플롯만 사용하여 범례를 작성하는 적절한 방법을 알아낼 수 없습니다.

답변1

내가 본 한 당신은 타악기의 대답을 다음과 같이 해석했습니다.pgfplots를 사용하여 동일한 스타일(주기 목록 사용)로 두 개의 선을 어떻게 그릴 수 있습니까?잘못. 한 그룹에 대한 플롯을 추가한 후 다음 그룹에 대한 플롯을 추가하면 안 됩니다. 모든 그룹의 첫 번째 플롯을 추가한 다음 두 번째 플롯을 추가해야 합니다.

\addplot 1 from Group 1
\addplot 1 from Group 2
\addplot 1 from Group 3
\addplot 1 from Group 4 ... then
\pgfplotsset{cycle list shift=-<number of Groups>}

그러나 이것은 환경으로 만들 수 있습니다. 이것이 당신에게 적합한지 확인하십시오(범례를 올바르게 얻으려면 아래와 같이 첫 번째 플롯에 범례를 추가하기만 하면 됩니다).

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\newcounter{plotscount}\setcounter{plotscount}{0}
\newcommand*{\nextplots}{\stepplots\pgfplotsset{cycle list shift=-\theplotscount}}
\newenvironment{groupofplots}[1]{\def\stepplots{\addtocounter{plotscount}{#1}}}{\setcounter{plotscount}{0}}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[domain=-1:2, samples=10]
      % First plot of each group
      \begin{groupofplots}{2}
        \addplot {1*x+1};\addlegendentry{Style 1}
        \addplot {2*x+1};\addlegendentry{Style 2}
        % Second plot of each group
        \nextplots
        \addplot {1*x+2};
        \addplot {2*x+2};
        % Third plot of each group
        \nextplots
        \addplot {1*x+3};
        \addplot {2*x+3};
      \end{groupofplots}
    \end{axis}
  \end{tikzpicture}
\end{document}

편집하다

실제로 cycle multi list언급한 대로 사용할 수 있습니다.

cycle multi list={color\nextlist [N of]mark list}

이 방법의 단점은 전설이 있다는 것입니다. 작동하게 할 수는 없었지만스테판 핀노우아래 주석에서 동일한 스타일을 가진 플롯에 대해 빈 범례를 제공하는 것이 가능합니다(물론 하나는 제외).

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
        domain=-1:2,
        samples=10,
        cycle multi list={color\nextlist [3 of]mark list}]
        \addplot {1*x+1};
        \addplot {1*x+2};
        \addplot {1*x+3};
        \addplot {2*x+4};
        \addplot {2*x+5};
        \addplot {2*x+6};
        \addplot {3*x+7};
        \addplot {3*x+8};
        \addplot {3*x+9};
        \legend{Style 1,,,Style 2,,,Style 3}
    \end{axis}
  \end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

forget plot이 기능을 사용하면 아주 간단한 해결책이 나올 것이라고 생각합니다 .

그러나 당신은 더미 데이터 테이블을 제공하지 않았고 범례 항목이 어디에서 왔는지 알려주지 않았기 때문에 여기에 예를 제시할 뿐입니다. 필요에 따라 조정할 수 있기를 바랍니다. 그렇지 않은 경우에는 질문을 좀 더 구체적으로 설명하고 그에 따라 편집하십시오.

솔루션 작동 방식에 대한 자세한 내용은 코드의 주석을 살펴보세요.

% used PGFPlots v1.14
    % just some dummy data
    \begin{filecontents}{test.txt}
        x   g1p1    g1p2    g1p3    g2p1    g2p2    g2p3    g3p1    g3p2
        0.0 0.00    0.25    0.50    1.00    1.25    1.50    2.00    2.25
        0.5 0.25    0.50    0.75    1.50    1.75    2.00    3.00    3.25
        1.0 0.50    0.75    1.00    2.00    2.25    2.50    4.00    4.25
        1.5 0.75    1.00    1.25    2.50    2.75    3.00    5.00    5.25
        2.0 1.00    1.25    1.50    3.00    3.25    3.50    6.00    6.25
        2.5 1.25    1.50    1.75    3.50    3.75    4.00    7.00    7.25
    \end{filecontents}
\documentclass[border=5pt]{standalone}
% to provide the `\ifnumequal' command
% (inspired by <http://texwelt.de/wissen/fragen/5066>)
\usepackage{etoolbox}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            legend pos=north west,
        ]
            % loop through the groups
            \foreach \g in {1,...,2} {
                % loop through the plots of the group
                \foreach \p [count=\pi] in {1,...,3} {
                    % if the current plot loop is the last one, i.e. no 3
                    % then don't forget the plot and add the legend entry
                    \ifnumequal{\pi}{3}{
                        \addplot table [x=x,y=g\g p\p] {test.txt};
                            \addlegendentryexpanded{g\g p\p}
                    % else forget the plot
                    % (that means, use the current cycle list style without
                    %  increasing the counter and don't account for a legend
                    %  entry)
                    }{
                        \addplot+ [forget plot]
                            table [x=x,y=g\g p\p] {test.txt};
                    }
                }
            }
            % here the same in for your last special case where no
            % "group" loop is needed any more
            \foreach \p [count=\pi] in {1,...,2} {
                \ifnumequal{\p}{2}{
                    \addplot table [x=x,y=g3p\p] {test.txt};
                        \addlegendentryexpanded{g3p\p}
                }{
                    \addplot+ [forget plot]
                        table [x=x,y=g3p\p] {test.txt};
                }
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

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

관련 정보