2

I'm new to LaTeX and I have a lot of small problems that all cause failure:

  1. I want my y-axis to start at 0 (not at -something arbitraty which it is now). I have tried ymin=0, but it does not respond.
  2. I want to use '<' instead of 'before'. I have tried \textless, but that gives me an error "TeX capacity exceeded, sorry [input stack size=5000]"
  3. I want the y-label to have a subscript:

    ylabel={Installed capacity (MW\textsubscript{p})}
    

    But this does not work

  4. I want to remove the ticks on the top and right of the figure.

  5. I want the bar labels to be easily readable (it's fine if the figure becomes wider)

Basically, I want to go from this excel graph into a nice LaTeX graph:

enter image description here

My code:

\documentclass[11pt, twoside, a4paper]{report}
\usepackage[left = 20mm, right = 20mm,  top = 20mm, bottom = 20mm]{geometry}
\usepackage{apacite}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.5}

\begin{document}
\chapter{Introduction}

\begin{tikzpicture}
\begin{axis}[
    ybar,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=-10},
    ylabel={Installed capacity (MWp)},
    symbolic x coords={before2014, 2014, 2015, 2016, 2017},
    xtick=data,
    nodes near coords,
    nodes near coords align={vertical},
]
\addplot coordinates {(before2014, 1.7) (2014, 3.0) (2015, 49.5) (2016, 
70.7) (2017, 396.5)};
\addplot coordinates {(before2014, 1.7) (2014, 4.7) (2015, 54.2) (2016, 
124.9)(2017, 521.4)};
\legend{Annual installed capacity, Cumulative installed capacity}
\end{axis}
\end{tikzpicture}
\end{document}

My graph so far:

enter image description here

1 Answer 1

2
  1. Use enlarge x limits instead of enlargelimits, then ymin=0 works.

  2. One way would be to use 2013 as the plotting coordinate, and specify the ticklabels explicitly with

    xticklabels={$<2014$, $2014$, $2015$, $2016$, $2017$}
    
  3. What does "not work" mean exactly? \textsubscript works fine here.

  4. For example add axis lines*=left. This removes the axis border as well. If you want to keep that, add xtick pos=bottom,ytick pos=left.

  5. Make the bars wider with bar width=<length>, and make the diagram wider with width.

enter image description here

\documentclass[11pt, twoside, a4paper]{report}
\usepackage[left = 20mm, right = 20mm,  top = 20mm, bottom = 20mm]{geometry}
\usepackage{apacite}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.5}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    % set width and height
    width=0.8\linewidth,
    height=0.4\linewidth,
    ybar,
    bar width=25pt, % make bars wider
    enlarge x limits=0.15, % only enlarge in x-direction
    ymin=0, % set ymin=0
    legend style={at={(0.5,-0.15)},
    anchor=north,legend columns=-10},
    ylabel={Installed capacity (MW\textsubscript{p})},
    xticklabels={$<2014$, $2014$, $2015$, $2016$, $2017$}, % set ticklabels explicitly
    xtick=data,
    nodes near coords,
    axis lines*=left, % remove border from top and right of axis
    % if you only want to remove the ticks, use this instead:
    % xtick pos=bottom,ytick pos=left,
    ymajorgrids % turn on grid for yticks (maybe not needed?)
]

% use 2013 as first x-coordinate
\addplot coordinates {(2013, 1.7) (2014, 3.0) (2015, 49.5) (2016, 
70.7) (2017, 396.5)};
\addplot coordinates {(2013, 1.7) (2014, 4.7) (2015, 54.2) (2016, 
124.9)(2017, 521.4)};
\legend{Annual installed capacity, Cumulative installed capacity}
\end{axis}
\end{tikzpicture}
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .