You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Hoje, possui sua própria API orientada a objetos.
23
29
<!-- #endregion -->
24
30
25
-
```{code-cell}
31
+
+++
32
+
33
+
Para trabalhar com o Matplotlib em notebooks Jupyter, podemos escolher o [backend interativo](https://matplotlib.org/stable/users/explain/figure/backends.html#interactive-backends) desejado:
34
+
35
+
```{code-cell} ipython3
26
36
%matplotlib widget
27
37
```
28
38
29
-
<!-- #region tags=["section"] -->
30
-
## O módulo `pyplot`
31
-
<!-- #endregion -->
39
+
## Interfaces: implícita (`matplotlib.pyplot`) e orientada a objetos
40
+
41
+
+++
42
+
43
+
Por razões históricas, o Matplotlib implementa uma interface explícita para acesso às funções de criações de gráficos - o módulo `pyplot`.
44
+
45
+
+++
32
46
33
-
```{code-cell}
47
+
### Exemplo
48
+
49
+
```{code-cell} ipython3
34
50
import matplotlib.pyplot as plt
35
51
```
36
52
37
-
```{code-cell}
53
+
```{code-cell} ipython3
38
54
print(plt.__doc__)
39
55
```
40
56
41
57
### Exemplo 1
42
58
43
-
```{code-cell}
59
+
```{code-cell} ipython3
44
60
import numpy as np
45
61
t = np.arange(-5, 5, 0.1)
46
62
```
47
63
48
-
```{code-cell}
64
+
```{code-cell} ipython3
49
65
plt.plot(t, t**2);
50
66
```
51
67
52
-
```{code-cell}
53
-
plt.plot(t, t**2, 'r*')
54
-
plt.close()
55
-
```
68
+
### API Orientada a objetos (recomendada)
56
69
57
-
```{code-cell}
58
-
plt.plot(t, t**2, linewidth=3)
59
-
plt.show()
60
-
```
70
+
+++
61
71
62
-
<!-- #region tags=["section"] -->
63
-
## Outra maneira: API Orientada a objetos
64
-
<!-- #endregion -->
72
+
A maneira moderna e recomendade de criar gráficos com o Matplotlib é através da API orientada a objetos. (Leia mais em https://matplotlib.org/stable/users/explain/figure/api_interfaces.html)
65
73
66
-
```{code-cell}
74
+
```{code-cell} ipython3
67
75
fig, ax = plt.subplots()
68
76
ax.plot(t, t**2, 'r*')
69
77
```
70
78
71
-
```{code-cell}
79
+
```{code-cell} ipython3
72
80
ax.plot(t, t**2, linewidth=3)
73
81
```
74
82
75
-
```{code-cell}
83
+
```{code-cell} ipython3
76
84
fig2, ax2 = plt.subplots()
77
-
ax2.plot(t, t**2, 'm--');
85
+
ax2.plot(t, t**2, 'm--'); # Acrescente um ponto-e-vírgula ao final da
0 commit comments