Building a bar chart

A classic way of displaying categories with corresponding values is a bar chart. It consists of rectangular bars, and they are proportional to the represented values. The main purpose is to visually compare those values.

We will draw a chart visualizing web forum statistics.

How to do it...

We will use the pgfplots package. It's for natively plotting in LaTeX with a convenient user interface. We will use it to produce a horizontal bar chart.

Perform these steps:

  1. Start with a document class:
    \documentclass{article} 
  2. Load the pgfplots package:
    \usepackage{pgfplots}
    \pgfplotsset{width=7cm,compat=1.8}
  3. Begin the document:
    \begin{document}
  4. Begin a TikZ picture, which will be the container for the plot:
    \begin{tikzpicture}
  5. Open an axis environment: ...

Get LaTeX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.