我对此图的 y 轴值感到困惑。我不知道如何调整 y 轴值以使图更“放松”(我不知道如何解释)
代码如下
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {Gráfico de Sedimentación},
%scale only axis,
axis lines = left,
xlabel = {Número de componente},
ylabel = {Autovalor},
xmin=0, xmax=5,
ymin=0, ymax=4,
xtick={1,2,3,4,5},
ytick={3.395,1.059,0.410,0.110,0.027},
yticklabel style={/pgf/number format/.cd,fixed,precision=3},
ymajorgrids=true,
grid style = dashed,
]
\addplot[
color=black,
mark = *,
]
coordinates {(1,3.395) (2,1.059) (3,0.410) (4,0.110) (5, 0.027)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我会将其制作成对数图。
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymode=log,
title = {Gr\'afico de Sedimentaci\'on},
%scale only axis,
axis lines = left,
xlabel = {N\'umero de componente},
ylabel = {Autovalor},
xmin=0, xmax=5,
ymin=0, ymax=4,
xtick={1,2,3,4,5},
ytick={3.395,1.059,0.410,0.110,0.027},
yticklabels={3.395,1.059,0.410,0.110,0.027},
yticklabel style={/pgf/number format/.cd,fixed,precision=3},
ymajorgrids=true,
grid style = dashed,
ylabel style={yshift=1em}
]
\addplot[
color=black,
mark = *,
]
coordinates {(1,3.395) (2,1.059) (3,0.410) (4,0.110) (5, 0.027)};
\end{axis}
\end{tikzpicture}
\end{document}
或者,如果您想保留您的图,请使用nodes near coords
。
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%ymode=log,
title = {Gr\'afico de Sedimentaci\'on},
%scale only axis,
axis lines = left,
xlabel = {N\'umero de componente},
ylabel = {Autovalor},
xmin=0, xmax=5,
ymin=0, ymax=4,
xtick={1,2,3,4,5},
ytick={3.395,1.059,0.410,0.110,0.027},
yticklabels={},
yticklabel style={/pgf/number format/.cd,fixed,precision=3},
ymajorgrids=true,
grid style = dashed,
ylabel style={yshift=1em},
nodes near coords
]
\addplot[
color=black,
mark = *,
]
coordinates {(1,3.395) (2,1.059) (3,0.410) (4,0.110) (5, 0.027)};
\end{axis}
\end{tikzpicture}
\end{document}