这一点我还没弄清楚。
这是一个非常基本的条形图,我symbolic x coords
试图显示年份。但是只显示了第一年,而且与它应该表示的列相差甚远。我试过使用xtick=data,
和xtick={2001,2002,...,2016},
,也试过xticklabel
而不是xtick
。
我的MWE
\documentclass[a4paper, twoside, BCOR=10mm]{scrbook}
%\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage[icelandic]{babel}
\usepackage{t1enc}
\usepackage{graphicx}
%\usepackage[intoc]{nomencl}
%\usepackage{enumerate,color}
\usepackage{url}
\usepackage[pdfborder={0 0 0}]{hyperref}
%\usepackage{appendix}
\usepackage{eso-pic}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{subfig}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{external}
\usepgfplotslibrary{dateplot}
\usepackage[format=plain,labelformat=simple,labelsep=colon]{caption}
%\usepackage{placeins}
\usepackage{tabularx}
\usepackage{graphicx}
\graphicspath{ {Myndir/} }
\usepackage[backend=biber, style=authoryear]{biblatex}
\usepackage{csquotes}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}[
ybar,
width=.9\linewidth,
height=8cm,
enlarge x limits = 0.33,
ybar=2pt,
bar width=4pt,
ymajorgrids=true,
grid style=dashed,
xlabel={Ár},
ylabel={Árleg uppsett vindorkugeta á heimsvísu (GW)},
symbolic x coords={2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016},
xtick=data,
% xticklabels={2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016},
legend columns=-1, % to set one line legend
legend style={at={(0.5,-0.35)},anchor=center},
% legend style={/tikz/every even column/.append style={column sep=2pt}},
nodes near coords,
nodes near coords align={vertical},
nodes near coords style={font=\tiny}
]
\addplot+[ybar, red] coordinates { (2001,6.5) };
\addplot+[ybar, red] coordinates { (2002,7.3)};
\addplot+[ybar, red] coordinates { (2003,8.1) };
\addplot+[ybar, red] coordinates { (2004,8.2) };
\addplot+[ybar, red] coordinates { (2005,11.5) };
\addplot+[ybar, red] coordinates { (2006,14.7) };
\addplot+[ybar, red] coordinates { (2007,20.3) };
\addplot+[ybar, red] coordinates { (2008,26.9) };
\addplot+[ybar, red] coordinates { (2009,38.5) };
\addplot+[ybar, red] coordinates { (2010,39.1) };
\addplot+[ybar, red] coordinates { (2011,40.6) };
\addplot+[ybar, red] coordinates { (2012,45.0) };
\addplot+[ybar, red] coordinates { (2013,36.0) };
\addplot+[ybar, red] coordinates { (2014,51.7) };
\addplot+[ybar, red] coordinates { (2015,63.6) };
\addplot+[ybar, red] coordinates { (2016,54.6) };
\end{axis}
\end{tikzpicture}
\caption{Árleg uppsett vindorkugeta á heimsvísu \protect\autocite{Alkhalidi} \label{fig:uppbygging}}
\end{figure}
\end{document}
我知道我需要减小此图表中符号 x 的字体大小。但我觉得很奇怪,我只得到一年。我甚至对周期标签也感到满意。
答案1
这是一个 tikz 程序,它显示了我认为你想要的图片。我没有足够的知识来指出你的程序中的错误,而是在 pgfplots 手册中找到了一个合理的例子: https://pgfplots.sourceforge.net/example_78.tex
\documentclass[tikz]{standalone}
\usepackage[icelandic]{babel}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=120mm,
height=8cm,
x tick label style={/pgf/number format/1000 sep=},
xmin=2000.20,xmax=2016.4,
xtick={2001,2002,...,2016},
x tick label style={font=\footnotesize,rotate=45,anchor=east},
ybar=2pt,
bar width=4pt,
ymajorgrids=true,
grid style=dashed,
xlabel={Ár},
ylabel={Árleg uppsett vindorkugeta á heimsvísu (GW)},
nodes near coords,
nodes near coords style={font=\tiny}
]
\addplot[red,fill] coordinates { (2001,6.5)(2002,7.3)
(2003,8.1)(2004,8.2) (2005,11.5)(2006,14.7)
(2007,20.3) (2008,26.9) (2009,38.5) (2010,39.1)
(2011,40.6) (2012,45.0) (2013,36.0) (2014,51.7)
(2015,63.6) (2016,54.6) };
\end{axis}
\end{tikzpicture}
\end{document}