pgfplots - 如何将背景填充到“坐标附近的节点”?

pgfplots - 如何将背景填充到“坐标附近的节点”?

我希望每个图的节点/值都用 填充white,这样网格就会被透支。这可能吗?

x(注意:我只是为了线程而激活了主网格。)

网格上有数字/节点的图片

平均能量损失

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
pgfplotstable
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{filecontents}{force-stats.txt}
Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
Fx,-70.35,0.5,0.6,60,1,0.5
Fy,-40,0.5,0.6,50,1.91,1.5
Fz,-20,0.42,0.6,40,4,0.5
\end{filecontents}

\pgfplotstableread[col sep=comma]{force-stats.txt}{\tableabcdef}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
scale only axis=true,
width=5cm,
height=7cm,
%
xlabel={Force components},
ylabel={Force in N},
%
ybar,
%
xmajorgrids=true,
ymajorgrids=true,
%
enlarge x limits={0.3},
enlarge y limits={0.2},
%
symbolic x coords={Fx,Fy,Fz},
%
xtick=data,
nodes near coords,
xticklabels={{\(F_{x}\)},{\(F_{y}\)},{\(F_{z}\)}},
]
\addplot+[nodes near coords align={above}] plot [error bars/.cd, y dir=both, y explicit] table [col sep=comma, x=Stats, y=Max, y error=MinCIP95] {\tableabcdef};
\addplot+[nodes near coords align={below}] plot [error bars/.cd, y dir=both, y explicit] table [col sep=comma, x=Stats, y=Min, y error=MinCIP95] {\tableabcdef};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

答案1

来自pgfplots手册:

/pgfplots/every node near coord (style, no value) 用于由坐标附近的节点生成的每个节点的样式。它最初是空的。

因此(Ctrl-F NEW在代码块中找到相关行):

\documentclass[
a4paper
]{scrartcl}

\usepackage{
  amsmath,
  tikz,
  pgfplots,
  pgfplotstable
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{filecontents}{force-stats.txt}
  Stats,Min,MinStdDev,MinCIP95,Max,MaxStdDev,MaxCIP95
  Fx,-70.35,0.5,0.6,60,1,0.5
  Fy,-40,0.5,0.6,50,1.91,1.5
  Fz,-20,0.42,0.6,40,4,0.5
\end{filecontents}

\pgfplotstableread[col sep=comma]{force-stats.txt}{\tableabcdef}

\begin{document}
\begin{center}
  \begin{tikzpicture}[font=\small]
    \begin{axis}[
      scale only axis=true,
      width=5cm,
      height=7cm,
      %
      xlabel={Force components},
      ylabel={Force in N},
      %
      ybar,
      %
      xmajorgrids=true,
      ymajorgrids=true,
      %
      enlarge x limits={0.3},
      enlarge y limits={0.2},
      %
      symbolic x coords={Fx,Fy,Fz},
      %
      xtick=data,
      nodes near coords,
      every node near coord/.style={fill=white},%NEW
      xticklabels={{\(F_{x}\)},{\(F_{y}\)},{\(F_{z}\)}},
      ]
      \addplot+[nodes near coords align={above}] plot [error bars/.cd, y dir=both, y explicit] table [col sep=comma, x=Stats, y=Max, y error=MinCIP95] {\tableabcdef};
      \addplot+[nodes near coords align={below}] plot [error bars/.cd, y dir=both, y explicit] table [col sep=comma, x=Stats, y=Min, y error=MinCIP95] {\tableabcdef};
    \end{axis}
  \end{tikzpicture}
\end{center}
\end{document}

将该选项添加到周围tikzpicture没有任何效果(我猜在这种情况下网格是稍后绘制的),但正如您所看到的,将其添加到作品中axis

但结果并不一定令人满意:

在此处输入图片描述

相关内容