我有以下图表...如果没有数据文件,下面的代码将无法构建,但后面会有图像
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
legend columns=4,
legend entries={{\tiny Random},{\tiny +Cost},{\tiny +FTE},{\tiny ++Cost},{\tiny ++FTE},{\tiny ++Resources}, {\tiny ++Cost$_{tri}$}, {\tiny ++FTE$_{tri}$}, {\tiny ++Resources$_{tri}$}, {\tiny ++Cost$_{LN}$}, {\tiny ++FTE$_{expo}$}, {\tiny ++Resources$_{expo}$}},
legend to name=DollarsLegend,
mark repeat=20,
xlabel = Simulation Day,
ylabel = Dollars Committed,
xmin=0,
xmax=260,
width=0.9\textwidth,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
scaled ticks=false,
yticklabel={${\$\pgfmathprintnumber{\tick}}$},
]
\addplot table[line join=round,col sep=comma, y=Random, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize Random}}
\addplot table[line join=round,col sep=comma, y=PlusCost, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize +Cost}}
\addplot table[line join=round,col sep=comma, y=PlusFTE, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize +FTE}}
\addplot table[line join=round,col sep=comma, y=PlusPlusCost, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost}}
\addplot table[line join=round,col sep=comma, y=PlusPlusFTE, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE}}
\addplot table[line join=round,col sep=comma, y=PlusPlusResources, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources}}
\addplot table[line join=round,col sep=comma, y=PlusPlusCostTri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost$_{tri}$}}
\addplot table[line join=round,col sep=comma, y=PlusPlusFTETri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE$_{tri}$}}
\addplot table[line join=round,col sep=comma, y=PlusPlusResourcesTri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources$_{tri}$}}
\addplot table[line join=round,col sep=comma, y=PlusPlusCostLN, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost$_{LN}$}}
\addplot table[line join=round,col sep=comma, y=PlusPlusFTEExpo, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE$_{expo}$}}
\addplot table[line join=round,col sep=comma, y=PlusPlusResourcesExpo, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources$_{expo}$}}
\end{axis}
\end{tikzpicture}
\ref{DollarsLegend}
\caption{Dollar Commitment versus Time}
\label{DollarCommitment}
\end{figure}
\end{document}
以下是结果图表
我需要准备黑白版,所以我需要确保每个系列都有一个无需颜色即可区分的标记。但是当我将线条修改\addplot
成这样时,例如
\addplot table[line join=round,col sep=comma, y=Random, x=Day, mark=triangle]{DollarCommitment.csv};
我得到了相同的图表……好像我的标记规范被忽略了。我做错了什么?
答案1
您必须添加mark=
(并且line join=round,
这也是您的练习)到\addplot
选项而不是table
选项中。
\addplot+[black,line join=round,mark=Mercedes star] table[line join=round,col sep=comma, y=PlusPlusFTEExpo, x=Day]{DollarCommitment.csv};
另外,您也可以使用 a cycle list
(而不是键入所有这些标记)。手册中提到了许多内置的标记,但您可以构建自己的标记(请参阅手册),例如:
cycle list name=black white,
代码:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
legend columns=4,
%legend entries={{\tiny Random},{\tiny +Cost},{\tiny +FTE},{\tiny ++Cost},{\tiny ++FTE},{\tiny ++Resources}, {\tiny ++Cost$_{tri}$}, {\tiny ++FTE$_{tri}$}, {\tiny ++Resources$_{tri}$}, {\tiny ++Cost$_{LN}$}, {\tiny ++FTE$_{expo}$}, {\tiny ++Resources$_{expo}$}},
legend to name=DollarsLegend,
%mark repeat=20, %% uncomment in your data
xlabel = Simulation Day,
ylabel = Dollars Committed,
xmin=0,
xmax=260,
width=0.9\textwidth,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
scaled ticks=false,
yticklabel={${\$\pgfmathprintnumber{\tick}}$},
%cycle list name=black white,
%every mark/.append style={fill=gray!10}
]
\addplot+[black,mark=o] table[line join=round,col sep=comma, y=Random, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize Random}}
\addplot+[black,mark=x] table[line join=round,col sep=comma, y=PlusCost, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize +Cost}}
\addplot+[black,mark=|] table[line join=round,col sep=comma, y=PlusFTE, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize +FTE}}
\addplot+[black,mark=square] table[line join=round,col sep=comma, y=PlusPlusCost, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost}}
\addplot+[black,mark=star] table[line join=round,col sep=comma, y=PlusPlusFTE, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE}}
\addplot+[black,mark=10-pointed star] table[line join=round,col sep=comma, y=PlusPlusResources, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources}}
\addplot+[black,mark=otimes] table[line join=round,col sep=comma, y=PlusPlusCostTri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost$_{tri}$}}
\addplot+[black,mark=oplus] table[line join=round,col sep=comma, y=PlusPlusFTETri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE$_{tri}$}}
\addplot+[black,mark=triangle] table[line join=round,col sep=comma, y=PlusPlusResourcesTri, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources$_{tri}$}}
\addplot+[black,mark=diamond] table[line join=round,col sep=comma, y=PlusPlusCostLN, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Cost$_{LN}$}}
\addplot+[black,mark=Mercedes star] table[line join=round,col sep=comma, y=PlusPlusFTEExpo, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++FTE$_{expo}$}}
\addplot+[black,mark=pentagon] table[line join=round,col sep=comma, y=PlusPlusResourcesExpo, x=Day]{DollarCommitment.csv};
\addlegendentry{{\scriptsize ++Resources$_{expo}$}}
\end{axis}
\end{tikzpicture}
\ref{DollarsLegend}
\caption{Dollar Commitment versus Time}
\label{DollarCommitment}
\end{figure}
\end{document}