答案1
nodes near coords
旨在在绘图点附近添加文本,默认情况下,它会在点上方添加 y 值。我将该选项添加到axis
,这将为所有绘图启用该功能。对于单个绘图,我指定了这些节点应如何定位(在示例中,在点本身上方/下方 10pt),例如使用nodes near coords align={above=10pt}
。ymajorgrids
仅打开水平网格线。将其添加到axis
选项中。图例的位置用设置
legend style
,见下面的代码,其中有一些注释。或许你也想要
axis lines*=left
。
(我当然没有你的数据文件,所以我绘制了一对线性函数。)
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = ,
xlabel = {X},
ylabel= {Y},
scale only axis,
ymajorgrids, % turn on horizontal grid lines
nodes near coords, % <-- adds y-values next to points
legend columns=-1, % legend entries distributed horizontally instead of vertically
legend style={
at={(0.5,1)}, % coordinates are relative to axis box, (0,0) in bottom left, (1,1) in top right
above, % place it above that coord
draw=none % remove frame of legend
},
samples=10 % just for example
]
\addplot+ [nodes near coords align={above=10pt}] {x};
\addplot+ [nodes near coords align={below=10pt}] {x-1};
\addlegendentry{Values}
\addlegendentry{Stuff}
\end{axis}
\end{tikzpicture}
\end{document}