对于下面给出的代码,当我绘制数据时,它显示如下:
这不正确,显示应该是这样的:
你能告诉我这里的问题是什么吗?
这是我的代码:
\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{
fit,
shapes,
pgfplots.groupplots,
}
\pgfplotsset{compat=newest}
\begin{filecontents*}{FIT_costsens.txt}
1 0.055 0.348
2 0.123 0.565
3 0.110 0.304
4 0.068 0.609
5 0.137 0.435
6 0.096 0.304
7 0.110 0.261
8 0.082 0.522
9 0.123 0.435
10 0.123 0.435
100 0.192 0.217
\end{filecontents*}
\begin{document}
\newcommand{\plotcompAdaBstJfe}{FIT_costsens.txt}
\begin{tikzpicture}
\begin{axis}[width=14cm,height=9cm,
legend pos=north east,
xlabel={Ratio},
ylabel={(\%)},
%ymax=30,
ymin=0,
smooth,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=3,
/tikz/.cd
},
grid=both,
every major grid/.style={gray, opacity=0.5}]
\addplot [line width=1.6pt,
mark=none,
mark options={scale=.65}]%
table[x index=0,y index=1,col sep=space] {\plotcompAdaBstJfe};
\addlegendentry{Type I};
\addplot [line width=1.6pt,
mark=none,
red,
mark options={scale=.65}]%
table[x index=0,y index=2,col sep=space] {\plotcompAdaBstJfe};
\addlegendentry{Type II};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
- 您的问题已通过@daleif 评论解决
- 清理图表代码(参见@John Kormylo 评论)并稍微重新排列
axis
和\addplot
选择后,我得到了您想要的结果:
\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\newcommand{\plotcompAdaBstJfe}{FIT_costsens.txt}
\begin{filecontents*}{FIT_costsens.txt}
1 0.055 0.348
2 0.123 0.565
3 0.110 0.304
4 0.068 0.609
5 0.137 0.435
6 0.096 0.304
7 0.110 0.261
8 0.082 0.522
9 0.123 0.435
10 0.123 0.435
100 0.192 0.217
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=14cm, height=9cm,
grid=both,
xlabel={Ratio},
ylabel={(\%)},
legend pos=north east,
ymin=0,
yticklabel style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=3,
},
no marks,
every axis plot post/.append style={line width=1.6pt},
]
\addplot table[x index=0,y index=1] {\plotcompAdaBstJfe};
\addlegendentry{Type I};
\addplot table[x index=0,y index=2] {\plotcompAdaBstJfe};
\addlegendentry{Type II};
\end{axis}
\end{tikzpicture}
\end{document}