我想在图中交换两种绘图颜色。请看一下这个:
如您所见,第二张图中省略了“短期”图。因此,为了减少研究这两个图时的混淆,我想将图 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}
另外,是否可以将这些图形并排放置?我尝试改变整个图形的大小,以便它们可以并排放置,但这看起来不太好。也许我可以尝试其他解决方案?
你见过这个问题吗:两个并排的身影?
同样,在缩放图块方面,有多种选择。
以下解决方案使用 minipages 来并排显示图形,并使用 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}