Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


cheat sheet matplotlib biginner, Resúmenes de Programación Informática

cheat sheet matplotlib biginner

Tipo: Resúmenes

2019/2020

Subido el 22/09/2020

johnny-osorio-gallego
johnny-osorio-gallego 🇨🇴

5

(1)

2 documentos

1 / 1

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Matplotlib for beginners
Matplotlib is a library for making 2D plots in Python. It is
designed with the philosophy that you should be able to
create simple plots with just a few commands:
1Initialize
import numpy as np
import matplotlib.pyplot as plt
2Prepare
X = np.linspace(0, 4*np.pi, 1000)
Y = np.sin(X)
3Render
fig, ax = plt.subplots()
ax.plot(X, Y)
fig.show()
4Observe
0 5 10 15 20 25 30
1.0
0.5
0.0
0.5
1.0
Choose
Matplotlib offers several kind of plots (see Gallery):
X = np.random.uniform(0, 1, 100)
Y = np.random.uniform(0, 1, 100)
ax.scatter(X, Y)
1234567
1
2
3
4
5
6
7
X = np.arange(10)
Y = np.random.uniform(1, 10, 10)
ax.bar(X, Y)
1234567
1
2
3
4
5
6
7
Z = np.random.uniform(0, 1, (8,8)
ax.imshow(Z)
1234567
1
2
3
4
5
6
7
Z = np.random.uniform(0, 1, (8,8)
ax.contourf(Z)
1234567
1
2
3
4
5
6
7
Z = np.random.uniform(0, 1, 4)
ax.pie(Z)
1234567
1
2
3
4
5
6
7
Z = np.random.normal(0, 1, 100)
ax.hist(Z)
1234567
1
11
21
31
41
51
61
71
X = np.arange(5)
Y = np.random.uniform(0,1,5)
ax.errorbar(X, Y, Y/4)
1234567
1
2
3
4
5
6
7
Z = np.random.normal(0,1,(100,3))
ax.boxplot(Z)
246
1
2
3
4
5
6
7
Tweak
You can modify pretty much anything in a plot, including lim-
its, colors, markers, line width and styles, ticks and ticks la-
bels, titles, etc.
X = np.linspace(0,10,100)
Y = np.sin(X)
ax.plot(X, Y, color=”black”)
1234567
1
2
3
4
5
6
7
X = np.linspace(0,10,100)
Y = np.sin(X)
ax.plot(X, Y, linestyle=”--”)
1234567
1
2
3
4
5
6
7
X = np.linspace(0,10,100)
Y = np.sin(X)
ax.plot(X, Y, linewidth=5)
1234567
1
2
3
4
5
6
7
X = np.linspace(0,10,100)
Y = np.sin(X)
ax.plot(X, Y, marker=”o”)
1234567
1
2
3
4
5
6
7
Organize
You can plot several data on the the same figure but you can
also split a figure in several subplots (named Axes):
X = np.linspace(0,10,100)
Y1, Y1 = np.sin(X), np.cos(X)
ax.plot(X, Y1, Y2)
1234567
1
2
3
4
5
6
7
fig, (ax1, ax2) = plt.subplots((2,1))
ax1.plot(X, Y1, color=”C1”)
ax2.plot(X, Y2, color=”C0”)
fig, (ax1, ax2) = plt.subplots((1,2))
ax1.plot(Y1, X, color=”C1”)
ax2.plot(Y2, X, color=”C0”)
Label (everything)
ax.plot(X, Y)
fig.suptitle(None)
ax.set_title(”A Sine wave”)
1234567
1
2
3
4
5
A Sine wave
ax.plot(X, Y)
ax.set_ylabel(None)
ax.set_xlabel(”Time”)
Time
Explore
Figures are shown with a graphical user interface that all-
lows to zoom and pan the figure, to navigate between the
different views and to show the value under the mouse.
Save (bitmap or vector format)
fig.savefig(”my-first-figure.png”, dpi=300)
fig.savefig(”my-first-figure.pdf”)
Matplotlib 3.2 handout for beginners. Copyright (c) 2020 Nicolas P. Rougier. Released
under a CC-BY International 4.0 License. Supported by NumFocus Grant #12345.

Vista previa parcial del texto

¡Descarga cheat sheet matplotlib biginner y más Resúmenes en PDF de Programación Informática solo en Docsity!

Matplotlib for beginners

Matplotlib is a library for making 2D plots in Python. It is designed with the philosophy that you should be able to create simple plots with just a few commands: 1 Initialize import numpy as np import matplotlib.pyplot as plt 2 Prepare X = np.linspace(0, 4*np.pi, 1000) Y = np.sin(X) 3 Render fig, ax = plt.subplots() ax.plot(X, Y) fig.show() 4 Observe 0 5 10 15 20 25 30

Choose Matplotlib offers several kind of plots (see Gallery): X = np.random.uniform(0, 1, 100) Y = np.random.uniform(0, 1, 100) ax.scatter(X, Y) 1234567

X = np.arange(10) Y = np.random.uniform(1, 10, 10) ax.bar(X, Y) 1234567

Z = np.random.uniform(0, 1, (8,8) ax.imshow(Z) 1234567

Z = np.random.uniform(0, 1, (8,8) ax.contourf(Z) 1234567

Z = np.random.uniform(0, 1, 4) ax.pie(Z) 1234567

Z = np.random.normal(0, 1, 100) ax.hist(Z) 1234567

X = np.arange(5) Y = np.random.uniform(0,1,5) ax.errorbar(X, Y, Y/4) 1234567

Z = np.random.normal(0,1,(100,3)) ax.boxplot(Z) 246

Tweak You can modify pretty much anything in a plot, including lim- its, colors, markers, line width and styles, ticks and ticks la- bels, titles, etc. X = np.linspace(0,10,100) Y = np.sin(X) ax.plot(X, Y, color=”black”) 1234567

X = np.linspace(0,10,100) Y = np.sin(X) ax.plot(X, Y, linestyle=”--”) 1234567

X = np.linspace(0,10,100) Y = np.sin(X) ax.plot(X, Y, linewidth=5) 1234567

X = np.linspace(0,10,100) Y = np.sin(X) ax.plot(X, Y, marker=”o”) 1234567

Organize You can plot several data on the the same figure but you can also split a figure in several subplots (named Axes ): X = np.linspace(0,10,100) Y1, Y1 = np.sin(X), np.cos(X) ax.plot(X, Y1, Y2) 1234567

fig, (ax1, ax2) = plt.subplots((2,1)) ax1.plot(X, Y1, color=”C1”) ax2.plot(X, Y2, color=”C0”) fig, (ax1, ax2) = plt.subplots((1,2)) ax1.plot(Y1, X, color=”C1”) ax2.plot(Y2, X, color=”C0”) Label (everything) ax.plot(X, Y) fig.suptitle(None) ax.set_title(”A Sine wave”) 1234567

A Sine wave ax.plot(X, Y) ax.set_ylabel(None) ax.set_xlabel(”Time”) Time Explore Figures are shown with a graphical user interface that all- lows to zoom and pan the figure, to navigate between the different views and to show the value under the mouse. Save (bitmap or vector format) fig.savefig(”my-first-figure.png”, dpi=300) fig.savefig(”my-first-figure.pdf”) Matplotlib 3.2 handout for beginners. Copyright (c) 2020 Nicolas P. Rougier. Released under a CC-BY International 4.0 License. Supported by NumFocus Grant #12345.