PacktLib: matplotlib Plotting Cookbook

matplotlib Plotting Cookbook


About the Author

About the Reviewers


First Steps


Installing matplotlib

Plotting one curve

Using NumPy

Plotting multiple curves

Plotting curves from file data

Plotting points

Plotting bar charts

Plotting multiple bar charts

Plotting stacked bar charts

Plotting back-to-back bar charts

Plotting pie charts

Plotting histograms

Plotting boxplots

Plotting triangulations

Customizing the Color and Styles


Defining your own colors

Using custom colors for scatter plots

Using custom colors for bar charts

Using custom colors for pie charts

Using custom colors for boxplots

Using colormaps for scatter plots

Using colormaps for bar charts

Controlling a line pattern and thickness

Controlling a fill pattern

Controlling a marker's style

Controlling a marker's size

Creating your own markers

Getting more control over markers

Creating your own color scheme

Working with Annotations


Adding a title

Using LaTeX-style notations

Adding a label to each axis

Adding text

Adding arrows

Adding a legend

Adding a grid

Adding lines

Adding shapes

Controlling tick spacing

Controlling tick labeling

Working with Figures


Compositing multiple figures

Scaling both the axes equally

Setting an axis range

Setting the aspect ratio

Inserting subfigures

Using a logarithmic scale

Using polar coordinates

Working with a File Output


Generating a PNG picture file

Handling transparency

Controlling the output resolution

Generating PDF or SVG documents

Handling multiple-page PDF documents

Working with Maps


Visualizing the content of a 2D array

Adding a colormap legend to a figure

Visualizing nonuniform 2D data

Visualizing a 2D scalar field

Visualizing contour lines

Visualizing a 2D vector field

Visualizing the streamlines of a 2D vector field

Working with 3D Figures


Creating 3D scatter plots

Creating 3D curve plots

Plotting a scalar field in 3D

Plotting a parametric 3D surface

Embedding 2D figures in a 3D figure

Creating a 3D bar plot

User Interface


Making a user-controllable plot

Integrating a plot to a Tkinter user interface

Integrating a plot to a wxWidgets user interface

Integrating a plot to a GTK user interface

Integrating a plot in a Pyglet application