Matplotlib for beginners
Matplotlib is a library for making 2D plots in Python. It is
Z = [Link](0, 1, (8, 8))
Organize
designed with the philosophy that you should be able to
create simple plots with just a few commands: You can plot several data on the same figure, but you can
[Link](Z) also split a figure in several subplots (named Axes):
1 Initialize
Z = [Link](0, 1, 4) X = [Link](0, 10, 100)
import numpy as np Y1, Y2 = [Link](X), [Link](X)
import [Link] as plt [Link](Z) [Link](X, Y1, X, Y2)
Z = [Link](0, 1, 100) fig, (ax1, ax2) = [Link](2, 1)
2 Prepare
[Link](X, Y1, color=”C1”)
X = [Link](0, 10*[Link], 1000) [Link](Z) [Link](X, Y2, color=”C0”)
Y = [Link](X)
X = [Link](5) fig, (ax1, ax2) = [Link](1, 2)
3 Render Y = [Link](0, 1, 5) [Link](Y1, X, color=”C1”)
[Link](X, Y, Y∕4) [Link](Y2, X, color=”C0”)
fig, ax = [Link]()
[Link](X, Y) Z = [Link](0, 1, (100, 3))
[Link]() Label (everything)
[Link](Z)
4 Observe A Sine wave
[Link](X, Y)
1.0 [Link](None)
0.5 Tweak ax.set_title(”A Sine wave”)
0.0
0.5 You can modify pretty much anything in a plot, including lim-
[Link](X, Y)
1.0 its, colors, markers, line width and styles, ticks and ticks la-
0 5 10 15 20 25 30 ax.set_ylabel(None)
bels, titles, etc.
ax.set_xlabel(”Time”)
Time
Choose X = [Link](0, 10, 100)
Y = [Link](X) Explore
Matplotlib offers several kind of plots (see Gallery): [Link](X, Y, color=”black”)
Figures are shown with a graphical user interface that al-
X = [Link](0, 1, 100) X = [Link](0, 10, 100) lows to zoom and pan the figure, to navigate between the
Y = [Link](0, 1, 100) Y = [Link](X) different views and to show the value under the mouse.
[Link](X, Y) [Link](X, Y, linestyle=”--”)
Save (bitmap or vector format)
X = [Link](10) X = [Link](0, 10, 100)
Y = [Link](1, 10, 10) Y = [Link](X)
[Link](X, Y) [Link](X, Y, linewidth=5) [Link](”[Link]”, dpi=300)
[Link](”[Link]”)
Z = [Link](0, 1, (8, 8)) X = [Link](0, 10, 100)
Y = [Link](X)
Matplotlib 3.10.8 handout for beginners. Copyright (c) 2021 Matplotlib Development
[Link](Z) [Link](X, Y, marker=”o”) Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS.