Reputation: 23
I was trying to decrease the size of the font in nodes near coords in the following code, but the only solution that I found to avoid the nodes numbers overlap was to decrease their number of decimal digits.
Any suggestions on how to decrease the font of nodes near 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}
Upvotes: 2
Views: 4639
Reputation: 38937
You can change the style with nodes near coords style={font=\tiny}
(or whatever size you like)
\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}
Upvotes: 3