但轴号和 y 标签重叠。我可以将 10^-2 更改为 0.0x 格式吗?这是代码。
\begin{tikzpicture}
\definecolor{color0}{rgb}{0,0.75,0.75}
\definecolor{color1}{rgb}{0.75,0,0.75}
\begin{axis}[
legend cell align={left},
legend style={draw=white!80.0!black},
tick align=outside,
tick pos=left,
x grid style={white!69.01960784313725!black},
xlabel={iter},
xmin=-0.45, xmax=9.45,
xtick style={color=black},
y grid style={white!69.01960784313725!black},
ylabel={validation loss},
ymin=0.02, ymax=0.15,
ytick style={color=black}
]
\addplot [semithick, blue]
table {%
0 1.34207456321716
1 0.174043665003777
2 0.0967515116870403
3 0.0754522081717849
4 0.0627007393673062
5 0.0568854154974222
6 0.0532613188970834
7 0.0480173872113228
8 0.0488547417262569
9 0.0495724179415964
};
\addlegendentry{sigmoid}
\addplot [semithick, green!50.0!black]
table {%
0 0.0815436790004373
1 0.0580678164817393
2 0.0577852327806875
3 0.0555352639421821
4 0.0451464612137526
5 0.0502317223999649
6 0.0461553418475669
7 0.0499271957382327
8 0.0516832734428579
9 0.0523206829108996
};
\addlegendentry{tanh}
\addplot [semithick, red]
table {%
0 0.0909673798661679
1 0.0690677527815104
2 0.047157009664597
3 0.0472306680250913
4 0.0443113675033441
5 0.0446281971708522
6 0.0425379556572996
7 0.0536474616983847
8 0.042482587704694
9 0.0449555881925859
};
\addlegendentry{ReLU}
\addplot [semithick, color0]
table {%
0 0.0677304680856876
1 0.0512181081962772
2 0.053441882751626
3 0.0453108992217341
4 0.0429848205171642
5 0.0480912580440643
6 0.0481986717274172
7 0.0428763461877579
8 0.0441146830013981
9 0.045795459733066
};
\addlegendentry{ELU}
\addplot [semithick, color1]
table {%
0 0.0734140924926382
1 0.0525769912943244
2 0.0428529946752125
3 0.0440804580784636
4 0.0386188347235729
5 0.0347992292554467
6 0.0406374371483398
7 0.0420104633183742
8 0.0371617442105591
9 0.0359923966706483
};
\addlegendentry{Swish}
\end{axis}
\end{tikzpicture}
答案1
最新版本的 pgfplots 不会出现此问题。假设您需要使用较旧的兼容模式,或者无论如何都想更改数字格式,您可以添加
yticklabel style={/pgf/number format/fixed}
到你的轴的选项。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.16}%<-also solves the problem
\begin{document}
\begin{tikzpicture}
\definecolor{color0}{rgb}{0,0.75,0.75}
\definecolor{color1}{rgb}{0.75,0,0.75}
\begin{axis}[
legend cell align={left},
legend style={draw=white!80.0!black},
tick align=outside,
tick pos=left,
x grid style={white!69.01960784313725!black},
xlabel={iter},
xmin=-0.45, xmax=9.45,
xtick style={color=black},
y grid style={white!69.01960784313725!black},
ylabel={validation loss},
ymin=0.02, ymax=0.15,
ytick style={color=black},
yticklabel style={/pgf/number format/fixed}
]
\addplot [semithick, blue]
table {%
0 1.34207456321716
1 0.174043665003777
2 0.0967515116870403
3 0.0754522081717849
4 0.0627007393673062
5 0.0568854154974222
6 0.0532613188970834
7 0.0480173872113228
8 0.0488547417262569
9 0.0495724179415964
};
\addlegendentry{sigmoid}
\addplot [semithick, green!50.0!black]
table {%
0 0.0815436790004373
1 0.0580678164817393
2 0.0577852327806875
3 0.0555352639421821
4 0.0451464612137526
5 0.0502317223999649
6 0.0461553418475669
7 0.0499271957382327
8 0.0516832734428579
9 0.0523206829108996
};
\addlegendentry{tanh}
\addplot [semithick, red]
table {%
0 0.0909673798661679
1 0.0690677527815104
2 0.047157009664597
3 0.0472306680250913
4 0.0443113675033441
5 0.0446281971708522
6 0.0425379556572996
7 0.0536474616983847
8 0.042482587704694
9 0.0449555881925859
};
\addlegendentry{ReLU}
\addplot [semithick, color0]
table {%
0 0.0677304680856876
1 0.0512181081962772
2 0.053441882751626
3 0.0453108992217341
4 0.0429848205171642
5 0.0480912580440643
6 0.0481986717274172
7 0.0428763461877579
8 0.0441146830013981
9 0.045795459733066
};
\addlegendentry{ELU}
\addplot [semithick, color1]
table {%
0 0.0734140924926382
1 0.0525769912943244
2 0.0428529946752125
3 0.0440804580784636
4 0.0386188347235729
5 0.0347992292554467
6 0.0406374371483398
7 0.0420104633183742
8 0.0371617442105591
9 0.0359923966706483
};
\addlegendentry{Swish}
\end{axis}
\end{tikzpicture}
\end{document}