我想知道为什么 y 轴没有显示完整的数字,即精度 = 4,尽管我有显示它所需的所有数字,所以:
100 0.895150425339557
200 0.900482595232357
300 0.903679079675768
400 0.905775901961456
500 0.906989289317474
600 0.907739560134421
700 0.908159905497467
800 0.908394225024818
900 0.908519432232782
1000 0.90861411822613
\documentclass{standalone}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
%\pgfplotsset{compat=1.16,width=0.98\textwidth}
\usepackage{tikz}
\usepackage[english]{babel} % multilenguaje
% grid style
\pgfdeclareplotmark{mystar}{
\node[star,star point ratio=2.25,minimum size=6pt,
inner sep=0pt,draw=black,solid,fill=red] {};
}
\decimalpoint
\begin{document}
% This file was created by matplotlib2tikz v0.7.4.
\begin{tikzpicture}
\begin{axis}[
axis line style={black},
legend cell align={left},
legend style={at={(0.7,0.8)}, anchor=west, draw=black},
tick align=outside,
x grid style={dashed,black!60},
xlabel={$K$},
xmajorticks=true,
xmin=55, xmax=1045,
xtick style={color=black},
y grid style={dashed,black!60},
ylabel={RMSE},
ymajorticks=true,
ymin=0.875453344823198, ymax=0.910193202673888,
ytick style={black},
xtick align=inside,
ytick align=inside,
grid = none,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=4
},
]
\addplot [mark =square*,mark options = {fill=blue},line width=1pt,blue, mark size=2.5pt]
table {%
100 0.895150425339557
200 0.900482595232357
300 0.903679079675768
400 0.905775901961456
500 0.906989289317474
600 0.907739560134421
700 0.908159905497467
800 0.908394225024818
900 0.908519432232782
1000 0.90861411822613
};
\addlegendentry{Bla1}
\addplot [mark =triangle*,mark options = {fill=red},line width=1pt,red, mark size=2.5pt]
table {%
100 0.885569549243323
200 0.887070668935957
300 0.888060950115143
400 0.888591579965093
500 0.888834814899663
600 0.888949909904719
700 0.889000205838998
800 0.889021628991577
900 0.889029473681479
1000 0.889031852416184
};
\addlegendentry{Bla2}
\addplot [mark=*,mark options = {fill=black},line width=1pt,black, mark size=2.5pt]
table {%
100 0.877032429270956
200 0.877298698387484
300 0.877426754279817
400 0.877456082749727
500 0.877463664128281
600 0.877464908640126
700 0.877464997368712
800 0.87746508858427
900 0.877465105556874
1000 0.877465107569633
};
\addlegendentry{Bla3}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
在的帮助下,我删除了get\pgfkeys{/pgf/number format/.cd,1000 sep={}}
中的逗号。1,000
1000
我还替换了ymin=0.875453344823198, ymax=0.910193202673888,
,ymin=0.875, ymax=0.91
以便将相应的刻度与 x 轴对齐。
按照precision=4
您的要求保留 4 位小数。由于相邻刻度之间的间隔为0.005
(3 位小数),因此第四位小数位仅用0
s 填充,正如使用 所要求的那样fixed zerofill
。为了解决这个问题,我们可以使用 更改间隔ytick distance=0.0025
:
\documentclass{standalone}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
\pgfkeys{/pgf/number format/.cd,1000 sep={}} %<----- Added to remove thousand separator
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis line style={black},
legend cell align={left},
legend style={at={(0.7,0.8)}, anchor=west, draw=black},
tick align=outside,
x grid style={dashed,black!60},
xlabel={$K$},
xmajorticks=true,
xmin=55, xmax=1045,
xtick style={color=black},
y grid style={dashed,black!60},
ylabel={RMSE},
ymajorticks=true,
ymin=0.875, ymax=0.91, %<----- Changed
ytick distance=0.0025, %<----- Added to change interval between ticks
ytick style={black},
xtick align=inside,
ytick align=inside,
grid = none,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=4
},
]
\addplot [mark =square*,mark options = {fill=blue},line width=1pt,blue, mark size=2.5pt]
table {%
100 0.895150425339557
200 0.900482595232357
300 0.903679079675768
400 0.905775901961456
500 0.906989289317474
600 0.907739560134421
700 0.908159905497467
800 0.908394225024818
900 0.908519432232782
1000 0.90861411822613
};
\addlegendentry{Bla1}
\addplot [mark =triangle*,mark options = {fill=red},line width=1pt,red, mark size=2.5pt]
table {%
100 0.885569549243323
200 0.887070668935957
300 0.888060950115143
400 0.888591579965093
500 0.888834814899663
600 0.888949909904719
700 0.889000205838998
800 0.889021628991577
900 0.889029473681479
1000 0.889031852416184
};
\addlegendentry{Bla2}
\addplot [mark=*,mark options = {fill=black},line width=1pt,black, mark size=2.5pt]
table {%
100 0.877032429270956
200 0.877298698387484
300 0.877426754279817
400 0.877456082749727
500 0.877463664128281
600 0.877464908640126
700 0.877464997368712
800 0.87746508858427
900 0.877465105556874
1000 0.877465107569633
};
\addlegendentry{Bla3}
\end{axis}
\end{tikzpicture}
\end{document}