Matplotlib tutorial for beginner

# rougier/matplotlib-tutorial

## Folders and files

NameName
Last commit message
Last commit date

Â

50 Commits

Â
Â

Â
Â

Â
Â

Â
Â

Â
Â

Â
Â

Â
Â

Â
Â

# Matplotlib tutorial

## Nicolas P. Rougier

Sources are available from github

You can test your installation before the tutorial using the check-installation.py script.

### Introduction

matplotlib is probably the single most used Python package for 2D-graphics. It provides both a very quick way to visualize data from Python and publication-quality figures in many formats. We are going to explore matplotlib in interactive mode covering most common cases.

#### IPython

IPython is an enhanced interactive Python shell that has lots of interesting features including named inputs and outputs, access to shell commands, improved debugging and much more. It allows interactive matplotlib sessions that have Matlab/Mathematica-like functionality.

#### pyplot

pyplot provides a convenient interface to the matplotlib object-oriented plotting library. It is modeled closely after Matlab(TM). Therefore, the majority of plotting commands in pyplot have Matlab(TM) analogs with similar arguments. Important commands are explained with interactive examples.

### Simple plot

In this section, we want to draw the cosine and sine functions on the same plot. Starting from the default settings, we'll enrich the figure step by step to make it nicer.

The first step is to get the data for the sine and cosine functions:

import numpy as np

X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C, S = np.cos(X), np.sin(X)

X is now a NumPy array with 256 values ranging from -Ď€ to +Ď€ (included). C is the cosine (256 values) and S is the sine (256 values).

To run the example, you can download each of the examples and run it using:

#### Colormaps

All colormaps can be reversed by appending _r. For instance, gray_r is the reverse of gray.

If you want to know more about colormaps, see Documenting the matplotlib colormaps.

Name Appearance
autumn
bone
cool
copper
flag
gray
hot
hsv
jet
pink
prism
spectral
spring
summer
winter
Name Appearance
gist_earth
gist_gray
gist_heat
gist_ncar
gist_rainbow
gist_stern
gist_yarg
##### Diverging
Name Appearance
BrBG
PiYG
PRGn
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral

Sequential .........

Name Appearance
Blues
BuGn
BuPu
GnBu
Greens
Greys
Oranges
OrRd
PuBu
PuBuGn
PuRd
Purples
RdPu
Reds
YlGn
YlGnBu
YlOrBr
YlOrRd
Name Appearance
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
##### Miscellaneous
Name Appearance
afmhot
binary
brg
bwr
coolwarm
CMRmap
cubehelix
gnuplot
gnuplot2
ocean
rainbow
seismic
terrain

Matplotlib tutorial for beginner

## Releases 1

Version 1.0 Latest
Aug 21, 2015

## Packages 0

No packages published