3

I want to swap two plot colors in my figure. Please take a look at this:

enter image description here

As you can see, the "short-run" graph is omitted in the second figure. Thus, in order to reduce confusions when studying the two figures, I want to change the color of the "short-run" in figure 1 to brown and of the "long-run" to red. This is my code:

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

I tried to insert red or brown into the \addplot table [y=ShortRun,col sep=semicolon], as suggested here, but it doesn't change anything. Can anyone help me please figuring out what I'm doing wrong?

Also, is it possible to have these figures side-by-side? I tried to change the size of the whole figure, so that they would fit next to each other, but this doesn't look very good. Maybe there are some other solutions I could try out?

Thanks for the help!

Malganas
  • 503
  • You could simply swap the order of the plots in the first figure ... in other words, in Figure 1, put \addplot for ShortRun after LongRun. – badroit Apr 24 '17 at 01:39

1 Answers1

4

Solution 1: Simply swap the order of plots in the first figure.

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

Solution 2: Change the plot colour in Figure 2 manually:

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

Note that the formating goes in \addplot[], not in ... table [], where + indicates append.


Solution 3: In Figure 2, skip ahead one in the cycle list (the sequence of styles applied to each successive plot). This can be done with \pgfplotsset{cycle list shift=1} as follows.

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

Also, is it possible to have these figures side-by-side? I tried to change the size of the whole figure, so that they would fit next to each other, but this doesn't look very good. Maybe there are some other solutions I could try out?

Have you seen this question: Two figures side by side?

Likewise, in terms of scaling your plots, there are various options.

The following solution uses minipages for side-by-side figures and resizebox to scale the plots accordingly:

\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}
badroit
  • 7,557
  • Thank you - this helped me perfectly! The problem with putting figures side-by-side was, that they were to broad - but the scaling did the trick. – Malganas Apr 24 '17 at 09:54