PacktLib: Python Data Visualization Cookbook

Python Data Visualization Cookbook


About the Author

About the Reviewers


Preparing Your Working Environment


Installing matplotlib, NumPy, and SciPy

Installing virtualenv and virtualenvwrapper

Installing matplotlib on Mac OS X

Installing matplotlib on Windows

Installing Python Imaging Library (PIL) for image processing

Installing a requests module

Customizing matplotlib's parameters in code

Customizing matplotlib's parameters per project

Knowing Your Data


Importing data from CSV

Importing data from Microsoft Excel files

Importing data from fixed-width datafiles

Importing data from tab-delimited files

Importing data from a JSON resource

Exporting data to JSON, CSV, and Excel

Importing data from a database

Cleaning up data from outliers

Reading files in chunks

Reading streaming data sources

Importing image data into NumPy arrays

Generating controlled random datasets

Smoothing the noise in real-world data

Drawing Your First Plots and Customizing Them


Defining plot types – bar, line, and stacked charts

Drawing a simple sine and cosine plot

Defining axis lengths and limits

Defining plot line styles, properties, and format strings

Setting ticks, labels, and grids

Adding a legend and annotations

Moving spines to the center

Making histograms

Making bar charts with error bars

Making pie charts count

Plotting with filled areas

Drawing scatter plots with colored markers

More Plots and Customizations


Setting the transparency and size of axis labels

Adding a shadow to the chart line

Adding a data table to the figure

Using subplots

Customizing grids

Creating contour plots

Filling an under-plot area

Drawing polar plots

Visualizing the filesystem tree using a polar bar

Making 3D Visualizations


Creating 3D bars

Creating 3D histograms

Animating in matplotlib

Animating with OpenGL

Plotting Charts with Images and Maps


Processing images with PIL

Plotting with images

Displaying an image with other plots in the figure

Plotting data on a map using Basemap

Plotting data on a map using Google Map API

Generating CAPTCHA images

Using Right Plots to Understand Data


Understanding logarithmic plots

Understanding spectrograms

Creating a stem plot

Drawing streamlines of vector flow

Using colormaps

Using scatter plots and histograms

Plotting the cross-correlation between two variables

Importance of autocorrelation

More on matplotlib Gems


Drawing barbs

Making a box and a whisker plot

Making Gantt charts

Making errorbars

Making use of text and font properties

Rendering text with LaTeX

Understanding the difference between pyplot and OO API