Python matplotlib

Tight Layout guide

Advanced plotting

Advanced plotting

  • Moving to object-based plotting
  • Figure size
  • Placing Axes
  • Twin axes
  • Controlling the appearance of plots
  • rc parameters
  • Adding a legend
  • Adding a colorbar
  • Custom ticks and labels
  • Artists, Patches, and Lines


How do I draw a grid onto a plot in Python? [closed]
Set figure object to bounding box of fig.get_tightbbox()
Definition of matplotlib.pyplot.axes.bbox


Usage Guide – Backends
matplotlib.use required before other imports clashes with pep8. Ignore or fix?

import matplotlib
matplotlib.use('GTK3Cairo')  # noqa
import matplotlib.pyplot as plt
ValueError: Unrecognized backend string 'gtk': valid strings are
['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo',
 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg',
 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']


$ sudo apt-get install texlive texlive-lang-german texlive-latex-extra 
$ sudo apt-get install dvipng
$ sudo apt-get install ghostscript-x

Text rendering With LaTeX


Display style in math mode

works: GTK3Agg
doesn't work: GTK3Cairo, TkCairo

Convert to PostScript / PDF

Poppler, a PDF rendering library
Xpdf, an open source viewer for Portable Document Format (PDF) files

Leave a Reply

Your email address will not be published. Required fields are marked *