latex - 减小条形图中“坐标附近的节点”中的字体大小#tikzpicture #pgfplots
问题描述
我试图在以下代码中减小坐标附近节点中的字体大小,但我发现避免节点编号重叠的唯一解决方案是减少它们的小数位数。
关于如何减少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}
解决方案
nodes near coords 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}
推荐阅读
- angular - 如何防止Angular中的两个API调用?
- kotlin - 从标准输入中获取最小数(解释代码)
- uber-api - 优步优惠券 API 集成
- javascript - Popup 如何向 Content 发送消息并获得持续响应,反之亦然?
- go - 如何正确地将记录器注入代码的数据库层?
- spring-boot - Webflux RSocket Server 使用 RSocketRequestor 向 Rsocket-js 客户端发送消息。响应者未接收
- django - 找不到 Django 中的模板
- java - 如何注册和消费来自 IEX Cloud 的服务器发送事件?
- html - 如何在伪选择器中添加多个内容?
- node.js - Gulp“任务从未定义:默认”