减小条形图#tikzpicture #pgfplots中“靠近坐标的节点”中的字体大小

问题描述 投票:0回答:1

我试图在下面的代码中减小coords附近的节点中字体的大小,但是我发现避免节点数字重叠的唯一解决方案是减少其十进制数字。

关于如何减少coords附近的节点]的字体的任何建议?

\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}

我在以下代码中尝试减小靠近坐标的节点中字体的大小,但是我发现避免节点数重叠的唯一解决方案是减少其十进制数...

latex pdflatex
1个回答
0
投票

您可以使用nodes near coords style={font=\tiny}(或您喜欢的任何大小)来更改样式

© www.soinside.com 2019 - 2024. All rights reserved.