latex - 减小条形图中 "nodes near coords"中的字体大小 #tikzpicture #pgfplots

标签 latex pdflatex

我试图在以下代码中减小坐标附近的节点中的字体大小,但我发现避免节点数字重叠的唯一解决方案是减少它们的小数位数.

关于如何减小坐标附近的节点的字体有什么建议吗?

\newcommand{\figureHeight}{0.5625} %% 16:9
\pgfplotsset{
    compat           = 1.13,
    grid             = major,
    enlarge x limits = 0,
    cycle list name  = tum,
    major grid style = {dotted},
    minor grid style = {dotted},
    width            = \hsize,
    %width            = \hsize * 0.9,
    height           = \hsize * 0.9 * \figureHeight,
    legend style     = { at = {(0.98,0.96)}, anchor = north east,}
}

\begin{figure}[thb]
    \centering

    \begin{tikzpicture}
    \begin{axis}[
    ybar               = 5pt, % configures `bar shift'
    xmajorgrids        = false,
    x tick label style = {
        /pgf/number format/1000 sep =},
    xtick              = { 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
    ylabel             = Energy Produced in TWh,
    enlarge x limits   = 0.1,
    ymin               = 0,
    ymax               = 125,
    bar width          = 4pt,
    legend style={at={(0.02,0.96)},anchor=north west},
    nodes near coords
    ]

    %Hidro
    \addplot coordinates { ( 2011 , 18 ) ( 2012 , 21 ) ( 2013 , 23 ) ( 2014 , 19 ) ( 2015 , 19 ) ( 2016 , 21 ) ( 2017 , 20 ) ( 2018 , 19 )};
    \addlegendentry{Hydro}

    %Biomass
    \addplot coordinates { ( 2011 , 34 ) ( 2012 , 40 ) ( 2013 , 41 ) ( 2014 , 43 ) ( 2015 , 44 ) ( 2016 , 45 ) ( 2017 , 45 ) ( 2018 , 45 )};
    \addlegendentry{Biomass}

    %Wind
    \addplot coordinates { ( 2011 , 50 ) ( 2012 , 52 ) ( 2013 , 53 ) ( 2014 , 59 ) ( 2015 , 81 ) ( 2016 , 80 ) ( 2017 , 106 ) ( 2018 , 111 )};
    \addlegendentry{Wind}

    %Solar
    \addplot coordinates { ( 2011 , 20 ) ( 2012 , 26 ) ( 2013 , 31 ) ( 2014 , 36 ) ( 2015 , 40 ) ( 2016 , 38 ) ( 2017 , 39 ) ( 2018 , 46 )};
    \addlegendentry{Solar}

    \end{axis}
    \end{tikzpicture}

    \caption{Energy from renewable sources in Germany}

    \label{fig:EnergyFromRenewablesGermany}
\end{figure}

最佳答案

您可以使用坐标 style={font=\tiny} 附近的节点来更改样式(或您喜欢的任何大小)

\documentclass{book}

\usepackage{pgfplots}
\newcommand{\figureHeight}{0.5625} %% 16:9
\pgfplotsset{
    compat           = 1.13,
    grid             = major,
    enlarge x limits = 0,
%    cycle list name  = tum,
    major grid style = {dotted},
    minor grid style = {dotted},
    width            = \hsize,
    %width            = \hsize * 0.9,
    height           = \hsize * 0.9 * \figureHeight,
    legend style     = { at = {(0.98,0.96)}, anchor = north east,},
}

\begin{document}



\begin{figure}[thb]
    \centering

    \begin{tikzpicture}
    \begin{axis}[
    ybar               = 5pt, % configures `bar shift'
    xmajorgrids        = false,
    x tick label style = {
        /pgf/number format/1000 sep =},
    xtick              = { 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018},
    ylabel             = Energy Produced in TWh,
    enlarge x limits   = 0.1,
    ymin               = 0,
    ymax               = 125,
    bar width          = 4pt,
    legend style={at={(0.02,0.96)},anchor=north west},
    nodes near coords,
    nodes near coords style={font=\tiny}    
    ]

    %Hidro
    \addplot coordinates { ( 2011 , 18 ) ( 2012 , 21 ) ( 2013 , 23 ) ( 2014 , 19 ) ( 2015 , 19 ) ( 2016 , 21 ) ( 2017 , 20 ) ( 2018 , 19 )};
    \addlegendentry{Hydro}

    %Biomass
    \addplot coordinates { ( 2011 , 34 ) ( 2012 , 40 ) ( 2013 , 41 ) ( 2014 , 43 ) ( 2015 , 44 ) ( 2016 , 45 ) ( 2017 , 45 ) ( 2018 , 45 )};
    \addlegendentry{Biomass}

    %Wind
    \addplot coordinates { ( 2011 , 50 ) ( 2012 , 52 ) ( 2013 , 53 ) ( 2014 , 59 ) ( 2015 , 81 ) ( 2016 , 80 ) ( 2017 , 106 ) ( 2018 , 111 )};
    \addlegendentry{Wind}

    %Solar
    \addplot coordinates { ( 2011 , 20 ) ( 2012 , 26 ) ( 2013 , 31 ) ( 2014 , 36 ) ( 2015 , 40 ) ( 2016 , 38 ) ( 2017 , 39 ) ( 2018 , 46 )};
    \addlegendentry{Solar}

    \end{axis}
    \end{tikzpicture}

    \caption{Energy from renewable sources in Germany}

    \label{fig:EnergyFromRenewablesGermany}
\end{figure}



\end{document}

enter image description here

关于latex - 减小条形图中 "nodes near coords"中的字体大小 #tikzpicture #pgfplots,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58545992/

相关文章:

python - 将 pandas 数据框保存为图像或 pdf 文档中的表格,并具有良好的多索引显示

r - KnitR,Text 和 Code block 的 Latex 条件显示

pdf - 显示在屏幕上与打印时的链接颜色不同?

python - 在 django 中渲染 Latex/MathJax 方程

latex - ^ 和 _ 宏之后出现的数字(为 : LaTeX limitation? )

c# - 如何从 Appharbor 应用程序运行外部可执行文件(HTML 到 PDF 生成)?

python - matplotlib 和 LaTeX - ! TeX 容量超出,抱歉 [主内存大小=3000000]

latex - 在 Latex 中添加整页数字,如何?

python - 将数据帧写入 tex 文件时删除索引

latex - 同一文件中多种语言的语法高亮 : StatWeave/SAS/LaTeX