Example: Bar chart

Published 2015-08-30 | Author: Stefan Kottwitz

A bar chart can be used for comparing values. Here we create a horizontal bar chart.

The pgfplots package provides an easy way. In this example, I reduced axis data to focus on the values. So I do not show x-axis and y-axis, or axis ticks.

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Bar chart

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Bar charts
% Author: Stefan Kottwitz
% https://www.packtpub.com/hardware-and-creative/latex-cookbook
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[title  = Contributions per category
                          at LaTeX-Community.org,
    xbar,
    y axis line style = { opacity = 0 },
    axis x line       = none,
    tickwidth         = 0pt,
    enlarge y limits  = 0.2,
    enlarge x limits  = 0.02,
    symbolic y coords = {LaTeX, Tools, Distributions, Editors},
    nodes near coords,
  ]
  \addplot coordinates { (57727,LaTeX)         (5672,Tools)
                         (2193,Distributions)  (11106,Editors) };
  \addplot coordinates { (14320,LaTeX)         (1615,Tools)
                         (560,Distributions)   (3075,Editors)  };
  \legend{Topics, Posts}
  \end{axis}
\end{tikzpicture}
\end{document}

Comments

Adding comments is currently not enabled.

Features
Tags
Other areas

Cookbook

LaTeX Beginners Guide

Limited discount 50%
coupon code tDRet6Y

Creative Commons License