図の 2 つのプロット色を交換したいです。次の図をご覧ください:
ご覧のとおり、2 番目の図では「短期」グラフが省略されています。したがって、2 つの図を研究する際の混乱を減らすために、図 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}
また、これらの図を並べて配置することは可能ですか? 互いに隣り合うように図全体のサイズを変更してみましたが、見た目はあまり良くありません。他に試せる解決策はあるでしょうか?
この質問を見たことはありますか:2つの図が並んでいる?
同様に、プロットのスケーリングに関しては、さまざまな選択肢があります。
次のソリューションでは、横並びの図にミニページを使用し、それに応じてプロットを拡大縮小するために resizebox を使用します。
\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}