플롯 색상 바꾸기

플롯 색상 바꾸기

내 그림에서 두 개의 플롯 색상을 바꾸고 싶습니다. 이것을 살펴보십시오:

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

보시다시피, 두 번째 그림에서는 "단기" 그래프가 생략되었습니다. 따라서 두 그림을 연구할 때 혼란을 줄이기 위해 그림 1의 "단기" 색상을 갈색으로, "장기" 색상을 빨간색으로 변경하고 싶습니다. 이것은 내 코드입니다.

\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}

\begin{filecontents}{\jobname Data1.csv} 
Price;OneSided;ShortRun;LongRun
5;8.7;4;20.3 
10;16;11.7;20.7 
15;22.2;18.2;21 
20;27.6;23.9;21.3 
30;36.3;33.1;21.7
40;43.2;40.3;22.1
50;48.8;46.2;22.4
60;53.3;50.9;22.6
70;57.1;54.9;22.8
80;60.4;58.3;23
90;63.1;61.3;23.1
100;65.6;63.8;23.3
\end{filecontents}

\begin{filecontents}{\jobname Data3.csv} 
Price;OneSided;LongRun
5;8.7;14.9 
10;16;17.5 
15;22.2;20.1 
20;27.6;22.7 
30;36.3;28
40;43.2;33.2
50;48.8;38.4
60;53.3;43.7
70;57.1;48.9
80;60.4;54.1
90;63.1;59.3
100;65.6;64.6
\end{filecontents}

\begin{document}
\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
{Comparison of critical diversion ratios over different prices.}
\label{PlotSymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{One-sided} 
\addplot table [y=ShortRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Short-run} 
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
\end{figure}

\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
 {Comparison of critical diversion ratios over different prices.}
\label{PlotASymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{One-sided} 
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
\end{figure}
\end{document} 

제안한 대로 red또는 brown에 삽입하려고 했습니다 .\addplot table [y=ShortRun,col sep=semicolon]여기, 하지만 아무것도 바뀌지 않습니다. 누구든지 내가 뭘 잘못하고 있는지 알아내도록 도와줄 수 있나요?

그리고, 이 그림들을 나란히 놓을 수도 있나요? 전체 피규어의 크기를 바꿔서 서로 맞물리게 하려고 했는데 별로 좋아보이지 않네요. 시도해 볼 수 있는 다른 솔루션이 있을까요?

도와 주셔서 감사합니다!

답변1

솔루션 1: 첫 번째 그림의 플롯 순서를 바꾸면 됩니다.

\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}

\begin{filecontents}{\jobname Data1.csv} 
Price;OneSided;ShortRun;LongRun
5;8.7;4;20.3 
10;16;11.7;20.7 
15;22.2;18.2;21 
20;27.6;23.9;21.3 
30;36.3;33.1;21.7
40;43.2;40.3;22.1
50;48.8;46.2;22.4
60;53.3;50.9;22.6
70;57.1;54.9;22.8
80;60.4;58.3;23
90;63.1;61.3;23.1
100;65.6;63.8;23.3
\end{filecontents}

\begin{filecontents}{\jobname Data3.csv} 
Price;OneSided;LongRun
5;8.7;14.9 
10;16;17.5 
15;22.2;20.1 
20;27.6;22.7 
30;36.3;28
40;43.2;33.2
50;48.8;38.4
60;53.3;43.7
70;57.1;48.9
80;60.4;54.1
90;63.1;59.3
100;65.6;64.6
\end{filecontents}

\begin{document}
\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
{Comparison of critical diversion ratios over different prices.}
\label{PlotSymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{One-sided} 
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Long-run}
\addplot table [y=ShortRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Short-run} 
\end{axis} 
\end{tikzpicture}
\end{figure}

\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
 {Comparison of critical diversion ratios over different prices.}
\label{PlotASymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{One-sided} 
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
\end{figure}
\end{document}

솔루션 2: 그림 2의 플롯 색상을 수동으로 변경합니다.

\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}

\begin{filecontents}{\jobname Data1.csv} 
Price;OneSided;ShortRun;LongRun
5;8.7;4;20.3 
10;16;11.7;20.7 
15;22.2;18.2;21 
20;27.6;23.9;21.3 
30;36.3;33.1;21.7
40;43.2;40.3;22.1
50;48.8;46.2;22.4
60;53.3;50.9;22.6
70;57.1;54.9;22.8
80;60.4;58.3;23
90;63.1;61.3;23.1
100;65.6;63.8;23.3
\end{filecontents}

\begin{filecontents}{\jobname Data3.csv} 
Price;OneSided;LongRun
5;8.7;14.9 
10;16;17.5 
15;22.2;20.1 
20;27.6;22.7 
30;36.3;28
40;43.2;33.2
50;48.8;38.4
60;53.3;43.7
70;57.1;48.9
80;60.4;54.1
90;63.1;59.3
100;65.6;64.6
\end{filecontents}

\begin{document}
\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
{Comparison of critical diversion ratios over different prices.}
\label{PlotSymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{One-sided}
\addplot table [y=ShortRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Short-run}  
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
\end{figure}

\begin{figure}
\caption[Comparison of critical diversion ratios over different prices]
 {Comparison of critical diversion ratios over different prices.}
\label{PlotASymmetrischDR}
\centering
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{One-sided} 
\addplot+[brown,mark=*,every mark/.append style={solid, fill=brown}] table [y=LongRun,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
\end{figure}
\end{document}

형식은 \addplot[]가 아닌 로 지정됩니다. ... table []여기서는 +추가를 나타냅니다.


솔루션 3: 그림 2에서는사이클 목록(각 연속 플롯에 적용되는 스타일의 순서) 이는 다음과 같이 수행할 수 있습니다 \pgfplotsset{cycle list shift=1}.

\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}

\begin{filecontents}{\jobname Data1.csv} 
    Price;OneSided;ShortRun;LongRun
    5;8.7;4;20.3 
    10;16;11.7;20.7 
    15;22.2;18.2;21 
    20;27.6;23.9;21.3 
    30;36.3;33.1;21.7
    40;43.2;40.3;22.1
    50;48.8;46.2;22.4
    60;53.3;50.9;22.6
    70;57.1;54.9;22.8
    80;60.4;58.3;23
    90;63.1;61.3;23.1
    100;65.6;63.8;23.3
\end{filecontents}

\begin{filecontents}{\jobname Data3.csv} 
    Price;OneSided;LongRun
    5;8.7;14.9 
    10;16;17.5 
    15;22.2;20.1 
    20;27.6;22.7 
    30;36.3;28
    40;43.2;33.2
    50;48.8;38.4
    60;53.3;43.7
    70;57.1;48.9
    80;60.4;54.1
    90;63.1;59.3
    100;65.6;64.6
\end{filecontents}

\begin{document}
    \begin{figure}
        \caption[Comparison of critical diversion ratios over different prices]
        {Comparison of critical diversion ratios over different prices.}
        \label{PlotSymmetrischDR}
        \centering
        \begin{tikzpicture} 
        \begin{axis}[style={auto},legend pos=north west,ymin=0, 
        %        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
        x tick label style={/pgf/number format/1000 sep=}, 
        xlabel={Price increase, in \%}, 
        y tick label style={/pgf/number format/1000 sep=}, 
        ylabel={Critical diversion ratio, in \%} 
        ] 
        \addplot table [y=OneSided,col sep=semicolon]  {\jobname Data1.csv}; 
        \addlegendentry{One-sided} 
        \addplot table [y=ShortRun,col sep=semicolon]  {\jobname Data1.csv}; 
        \addlegendentry{Short-run} 
        \addplot table [y=LongRun,col sep=semicolon]  {\jobname Data1.csv}; 
        \addlegendentry{Long-run}
        \end{axis} 
        \end{tikzpicture}
    \end{figure}

    \begin{figure}
        \caption[Comparison of critical diversion ratios over different prices]
        {Comparison of critical diversion ratios over different prices.}
        \label{PlotASymmetrischDR}
        \centering
        \begin{tikzpicture} 
        \begin{axis}[style={auto},legend pos=north west,ymin=0, 
        %        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
        x tick label style={/pgf/number format/1000 sep=}, 
        xlabel={Price increase, in \%}, 
        y tick label style={/pgf/number format/1000 sep=}, 
        ylabel={Critical diversion ratio, in \%} 
        ] 
        \addplot table [y=OneSided,col sep=semicolon]  {\jobname Data3.csv}; 
        \addlegendentry{One-sided} 
        \pgfplotsset{cycle list shift=1}
        \addplot table [y=LongRun,col sep=semicolon]  {\jobname Data3.csv}; 
        \addlegendentry{Long-run}
        \end{axis} 
        \end{tikzpicture}
    \end{figure}
\end{document} 

그리고, 이 그림들을 나란히 놓을 수도 있나요? 전체 피규어의 크기를 바꿔서 서로 맞물리게 하려고 했는데 별로 좋아보이지 않네요. 시도해 볼 수 있는 다른 솔루션이 있을까요?

이 질문을 본 적이 있습니까?두 인물이 나란히?

마찬가지로 플롯 크기 조정 측면에서다양한 옵션이 있어요.

다음 솔루션은 병렬 그림에 미니페이지를 사용하고 크기 조정 상자를 사용하여 그에 따라 플롯의 크기를 조정합니다.

\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}

\begin{filecontents}{\jobname Data1.csv} 
Price;OneSided;ShortRun;LongRun
5;8.7;4;20.3 
10;16;11.7;20.7 
15;22.2;18.2;21 
20;27.6;23.9;21.3 
30;36.3;33.1;21.7
40;43.2;40.3;22.1
50;48.8;46.2;22.4
60;53.3;50.9;22.6
70;57.1;54.9;22.8
80;60.4;58.3;23
90;63.1;61.3;23.1
100;65.6;63.8;23.3
\end{filecontents}

\begin{filecontents}{\jobname Data3.csv} 
Price;OneSided;LongRun
5;8.7;14.9 
10;16;17.5 
15;22.2;20.1 
20;27.6;22.7 
30;36.3;28
40;43.2;33.2
50;48.8;38.4
60;53.3;43.7
70;57.1;48.9
80;60.4;54.1
90;63.1;59.3
100;65.6;64.6
\end{filecontents}

\begin{document}
\begin{figure}
\centering
\begin{minipage}{0.49\textwidth}
\caption[Comparison of critical diversion ratios over different prices]
{Comparison of critical diversion ratios over different prices.}
\label{PlotSymmetrischDR}
\centering
\resizebox{\textwidth}{!}{
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{One-sided}
\addplot table [y=ShortRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Short-run}  
\addplot table [y=LongRun,col sep=semicolon]  {\jobname Data1.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
}
\end{minipage}
\hfill
\begin{minipage}{0.49\textwidth}
\caption[Comparison of critical diversion ratios over different prices]
 {Comparison of critical diversion ratios over different prices.}
\label{PlotASymmetrischDR}
\centering
\resizebox{\textwidth}{!}{
\begin{tikzpicture} 
\begin{axis}[style={auto},legend pos=north west,ymin=0, 
%        xtick={5,10,15,20,25,30,40,50,60,70,80,90,100}, 
     x tick label style={/pgf/number format/1000 sep=}, 
     xlabel={Price increase, in \%}, 
     y tick label style={/pgf/number format/1000 sep=}, 
     ylabel={Critical diversion ratio, in \%} 
     ] 
\addplot table [y=OneSided,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{One-sided} 
\addplot+[brown,mark=*,every mark/.append style={solid, fill=brown}] table [y=LongRun,col sep=semicolon]  {\jobname Data3.csv}; 
\addlegendentry{Long-run}
\end{axis} 
\end{tikzpicture}
}
\end{minipage}
\end{figure}
\end{document}

관련 정보