# TikZ and pgfplots chart examples

> Plots and charts in TikZ with code, mostly pgfplots: grouped and stacked bar charts, pie charts, line charts, filled curves, polar and 3D surface plots.

URL: https://www.labcanvas.com/tikz/examples/plots-and-charts

Sixteen plots and charts: function plots (two intersecting curves, the area between curves, a spiral on polar axes), 3D plots (a 3D bar plot, a colour-blind-friendly mesh, a viridis surface), seven bar and pie charts and three line and area charts. Most come from the code of Stefan Kottwitz’s book *LaTeX Graphics with TikZ* and from Martin Thoma’s examples.

Fourteen of the sixteen are made with pgfplots, which draws the axes, ticks and legends for you; the two pie charts use the pgf-pie package.

## Function plots

- **Intersection of two curves** (Function plots): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/13-plotting/06-intersection.tex. Code: https://www.labcanvas.com/tikz-library/code/intersection-of-two-curves.tex
- **Filling between curves** (Function plots): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/13-plotting/08-filling-between-curves.tex. Code: https://www.labcanvas.com/tikz-library/code/filling-between-curves.tex
- **Spiral in polar axes** (Function plots): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/13-plotting/12-spiral-polar.tex. Code: https://www.labcanvas.com/tikz-library/code/spiral-in-polar-axes.tex

## 3D plots

- **3D bar plot** (3D plots): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/3d-manhattan-bar-plot/3d-manhattan-bar-plot.tex. Code: https://www.labcanvas.com/tikz-library/code/3d-bar-plot.tex
- **Colour-blind-friendly mesh plot** (3D plots): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/color-blind-friendly-mesh-colormap/color-blind-friendly-mesh-colormap.tex. Code: https://www.labcanvas.com/tikz-library/code/colour-blind-friendly-mesh-plot.tex
- **Surface plot (viridis)** (3D plots): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/hypersurface-2/hypersurface-2.tex. Code: https://www.labcanvas.com/tikz-library/code/surface-plot-viridis.tex

## Bar & pie charts

- **Bar chart with value labels** (Bar & pie charts): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/bar-chart-military-budget/bar-chart-military-budget.tex. Code: https://www.labcanvas.com/tikz-library/code/bar-chart-with-value-labels.tex
- **Pie chart (pgf-pie)** (Bar & pie charts): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/pie-chart/pie-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/pie-chart-pgf-pie.tex
- **Grouped bar chart** (Bar & pie charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/13-bar-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/grouped-bar-chart.tex
- **Stacked bar chart** (Bar & pie charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/14-bar-chart-stacked.tex. Code: https://www.labcanvas.com/tikz-library/code/stacked-bar-chart.tex
- **Horizontal bar chart** (Bar & pie charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/15-horizontal-bar-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/horizontal-bar-chart.tex
- **Pie chart (percentages)** (Bar & pie charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/17-pie-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/pie-chart-percentages.tex
- **Stacked bar chart (publications per year)** (Bar & pie charts): MIT licence, © Andreas Bauer. Source: https://github.com/andreas-bauer/tikz/blob/f17e1dc749c2b7981f54ee7e696a73273d6771b6/stacked-bar-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/stacked-bar-chart-publications-per-year.tex

## Line & area charts

- **Line chart with annotations** (Line & area charts): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/line-chart-electric-vehicles-sold/line-chart-electric-vehicles-sold.tex. Code: https://www.labcanvas.com/tikz-library/code/line-chart-with-annotations.tex
- **Line chart with markers** (Line & area charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/11-line-chart.tex. Code: https://www.labcanvas.com/tikz-library/code/line-chart-with-markers.tex
- **Stacked area chart** (Line & area charts): MIT licence, © Packt (code from LaTeX Graphics with TikZ by Stefan Kottwitz). Source: https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/blob/82e099639f46ee92bc622a01c739e7f7a3e87f4b/14-diagrams/12-line-chart-stacked.tex. Code: https://www.labcanvas.com/tikz-library/code/stacked-area-chart.tex

## Using these figures

Every figure keeps its own licence: MIT or CC0 1.0, both of which allow use, change and sharing, commercial use included. The MIT licence asks that its copyright and permission notice go with copies of the code, so each figure’s code starts with its source, author and licence; keep those lines when you reuse it. The full licence texts are on the [sources and licences page](https://www.labcanvas.com/tikz-library/credits.html).

“Open in the TikZ editor” loads the figure’s complete document into the free TikZ editor, where it is typeset with TeX Live 2026 and you can change it and download a PNG. To compile it on your own computer, save the code as a.tex file and run pdfLaTeX (or the engine the tile names) on it; LabCanvas changed the files only where needed to make each one compile on its own, as its first lines say.

Licence texts: https://www.labcanvas.com/tikz-library/credits.html
