平均能量损失

平均能量损失

我在序言中使用了这种样式定义:

\pgfplotsset{
  base/.style={
    ymin=0,
    xtick=data,
    nodes near coords,
  }
}

\pgfplotsset{
  random/.style={
    ybar=3pt,
    bar width=10pt,
    enlarge x limits=0.08,
    tick label style={font=\small},
    every axis y label/.style={at={(-0.06,0.5)},rotate=90},
    every node near coord/.append style={font=\scriptsize},
    every axis legend/.append style={font=\small},
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1, style={font=\small}},
    legend style={/tikz/every even column/.append style={column sep=0.4cm}}
  }
}

创建以下 tikzpicture:

\begin{tikzpicture}
  \begin{axis}[
      width=12.6cm,
      base,
      random,
      ylabel={\%},
      symbolic x coords={Google,Facebook,YouTube,Yahoo,Baidu,Wikipedia,QQ,Twitter,Taobao,Amazon},
      x tick label style={rotate=45, anchor=east}
    ]
\addplot coordinates {
      (Google,1.33)
      (Facebook,1.83)
      (YouTube,1.06)
      (Yahoo,1.38)
      (Baidu,0)
      (Wikipedia,3.13)
      (QQ,0)
      (Twitter,1.47)
      (Taobao,1.00)
      (Amazon,1.09)
    };
    \addplot coordinates {
      (Google,1.59)
      (Facebook,2.16)
      (YouTube,2.76)
      (Yahoo,1.61)
      (Baidu,0)
      (Wikipedia,3.13)
      (QQ,0)
      (Twitter,2.41)
      (Taobao,3.19)
      (Amazon,1.33)
    };
    \legend{Separated, Cascaded}
  \end{axis}
\end{tikzpicture}

正如您在维基百科条目中看到的,节点编号重叠:

输出图像

字体大小已经很小了,所以我不想减小它。

我怎样才能为奇数列和偶数列的节点设置不同的样式?

谢谢!

答案1

every node near coord/.append style={xshift=<dim>}我会通过使用键和 命令\addplot+(而不是)将蓝色列上的节点稍微向左移动,将红色列上的节点稍微向右移动\addplot

平均能量损失

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}

\pgfplotsset{
  base/.style={
    ymin=0,
    xtick=data,
    nodes near coords,
  }
}

\pgfplotsset{
  random/.style={
    ybar=3pt,
    bar width=10pt,
    enlarge x limits=0.08,
    tick label style={font=\small},
    every axis y label/.style={at={(-0.06,0.5)},rotate=90},
    every node near coord/.append style={font=\scriptsize},
    every axis legend/.append style={font=\small},
    legend style={at={(0.5,-0.2)},
      anchor=north,legend columns=-1, style={font=\small}},
    legend style={/tikz/every even column/.append style={column sep=0.4cm}}
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      width=12.6cm,
      base,
      random,
      ylabel={\%},
      symbolic x coords={Google,Facebook,YouTube,Yahoo,Baidu,Wikipedia,QQ,Twitter,Taobao,Amazon},
      x tick label style={rotate=45, anchor=east}
    ]
    \addplot+[every node near coord/.append style={xshift=-0.75pt}] coordinates {
      (Google,1.33)
      (Facebook,1.83)
      (YouTube,1.06)
      (Yahoo,1.38)
      (Baidu,0)
      (Wikipedia,3.13)
      (QQ,0)
      (Twitter,1.47)
      (Taobao,1.00)
      (Amazon,1.09)
    };
    \addplot+[every node near coord/.append style={xshift=0.75pt}] coordinates {
      (Google,1.59)
      (Facebook,2.16)
      (YouTube,2.76)
      (Yahoo,1.61)
      (Baidu,0)
      (Wikipedia,3.13)
      (QQ,0)
      (Twitter,2.41)
      (Taobao,3.19)
      (Amazon,1.33)
    };
    \legend{Separated, Cascaded}
  \end{axis}
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容