Table of Contents Preface 1 Chapter 1: Preparing Your Working Environment 5 Introduction 5 Installing matplotlib, NumPy, and SciPy 6 Installing virtualenv and virtualenvwrapper 8 Installing matplotlib on Mac OS X 10 Installing matplotlib on Windows 11 Installing Python Imaging Library (PIL) for image processing 12 Installing a requests module 14 Customizing matplotlib's parameters in code 14 Customizing matplotlib's parameters per project 16 Chapter 2: Knowing Your Data 19 Introduction 19 Importing data from CSV 20 Importing data from Microsoft Excel files 22 Importing data from fixed-width datafiles 25 Importing data from tab-delimited files 27 Importing data from a JSON resource 28 Exporting data to JSON, CSV, and Excel 31 Importing data from a database 36 Cleaning up data from outliers 40 Reading files in chunks 46 Reading streaming data sources 48 Importing image data into NumPy arrays 50 Generating controlled random datasets 56 Smoothing the noise in real-world data 64 Chapter 3: Drawing Your First Plots and Customizing Them 71 Introduction 72 Defining plot types – bar, line, and stacked charts 72 Drawing a simple sine and cosine plot 78 Defining axis lengths and limits 81 Defining plot line styles, properties, and format strings 84 Setting ticks, labels, and grids 89 Adding a legend and annotations 92 Moving spines to the center 95 Making histograms 96 Making bar charts with error bars 99 Making pie charts count 101 Plotting with filled areas 103 Drawing scatter plots with colored markers 105 Chapter 4: More Plots and Customizations 109 Introduction 109 Setting the transparency and size of axis labels 110 Adding a shadow to the chart line 113 Adding a data table to the figure 116 Using subplots 118 Customizing grids 121 Creating contour plots 125 Filling an under-plot area 128 Drawing polar plots 131 Visualizing the filesystem tree using a polar bar 134 Chapter 5: Making 3D Visualizations 139 Introduction 139 Creating 3D bars 139 Creating 3D histograms 143 Animating in matplotlib 146 Animating with OpenGL 150 Chapter 6: Plotting Charts with Images and Maps 157 Introduction 157 Processing images with PIL 158 Plotting with images 164 Displaying an image with other plots in the figure 168 Plotting data on a map using Basemap 172 Plotting data on a map using Google Map API 177 Generating CAPTCHA images 183 Chapter 7: Using Right Plots to Understand Data 189 Introduction 189 Understanding logarithmic plots 190 Understanding spectrograms 193 Creating a stem plot 198 Drawing streamlines of vector flow 201 Using colormaps 205 Using scatter plots and histograms 210 Plotting the cross-correlation between two variables 217 Importance of autocorrelation 220 Chapter 8: More on matplotlib Gems 225 Introduction 225 Drawing barbs 225 Making a box and a whisker plot 229 Making Gantt charts 232 Making errorbars 237 Making use of text and font properties 240 Rendering text with LaTeX 246 Understanding the difference between pyplot and OO API 250 Index 257