Skip to content

Commit f5009ea

Browse files
committed
Atualizar notebook matplotlib
1 parent 92222b9 commit f5009ea

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed
Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
---
22
jupytext:
33
formats: md:myst
4-
text_representation:
5-
extension: .md
6-
format_name: myst
74
kernelspec:
85
display_name: Python 3 (ipykernel)
96
language: python
107
name: python3
8+
text_representation:
9+
extension: .md
10+
format_name: myst
11+
format_version: 0.13
12+
jupytext_version: 1.16.4
13+
kernelspec:
14+
display_name: Python 3 (ipykernel)
15+
language: python
16+
name: python3
1117
---
1218

13-
```{code-cell}
19+
```{code-cell} ipython3
1420
from IPython.display import Image
15-
Image(url="https://matplotlib.org/_static/logo2_compressed.svg", width=600)
21+
Image(url="https://matplotlib.org/_static/logo_light.svg")
1622
```
1723

1824
<!-- #region tags=["chapter"] -->
@@ -22,89 +28,92 @@ Image(url="https://matplotlib.org/_static/logo2_compressed.svg", width=600)
2228
- Hoje, possui sua própria API orientada a objetos.
2329
<!-- #endregion -->
2430

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
2636
%matplotlib widget
2737
```
2838

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+
+++
3246

33-
```{code-cell}
47+
### Exemplo
48+
49+
```{code-cell} ipython3
3450
import matplotlib.pyplot as plt
3551
```
3652

37-
```{code-cell}
53+
```{code-cell} ipython3
3854
print(plt.__doc__)
3955
```
4056

4157
### Exemplo 1
4258

43-
```{code-cell}
59+
```{code-cell} ipython3
4460
import numpy as np
4561
t = np.arange(-5, 5, 0.1)
4662
```
4763

48-
```{code-cell}
64+
```{code-cell} ipython3
4965
plt.plot(t, t**2);
5066
```
5167

52-
```{code-cell}
53-
plt.plot(t, t**2, 'r*')
54-
plt.close()
55-
```
68+
### API Orientada a objetos (recomendada)
5669

57-
```{code-cell}
58-
plt.plot(t, t**2, linewidth=3)
59-
plt.show()
60-
```
70+
+++
6171

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)
6573

66-
```{code-cell}
74+
```{code-cell} ipython3
6775
fig, ax = plt.subplots()
6876
ax.plot(t, t**2, 'r*')
6977
```
7078

71-
```{code-cell}
79+
```{code-cell} ipython3
7280
ax.plot(t, t**2, linewidth=3)
7381
```
7482

75-
```{code-cell}
83+
```{code-cell} ipython3
7684
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
86+
# linha para não imprimir uma mensagem
7887
```
7988

8089
## Customização
8190

82-
```{code-cell}
91+
```{code-cell} ipython3
8392
fig, ax = plt.subplots()
8493
ax.plot(t, t**2, 'm--');
8594
```
8695

87-
```{code-cell}
96+
```{code-cell} ipython3
8897
fig
8998
```
9099

91-
```{code-cell}
100+
```{code-cell} ipython3
92101
fig.clear()
93102
```
94103

95-
```{code-cell}
104+
```{code-cell} ipython3
96105
fig.set_facecolor('black')
97106
```
98107

99108
## Exemplo boxplot
100109

101110

102-
https://matplotlib.org/search.html?q=boxplot
111+
https://matplotlib.org/stable/gallery/statistics/boxplot_demo.html
103112

104113

105114
## Exemplo 3D
106115

107-
```{code-cell}
116+
```{code-cell} ipython3
108117
import matplotlib.pyplot as plt
109118
import numpy as np
110119
@@ -128,26 +137,33 @@ ax.zaxis.set_major_formatter("{x:.02f}")
128137
fig.colorbar(surf, shrink=0.5, aspect=5)
129138
130139
plt.show()
131-
132140
```
133141

134142
## Guia do usuário: galeria e exemplos
135143

136144
- https://matplotlib.org/tutorials/introductory/usage.html
137145
- https://matplotlib.org/tutorials/introductory/usage.html#parts-of-a-figure
138146

139-
```{code-cell}
147+
```{code-cell} ipython3
140148
Image(url="https://matplotlib.org/_images/anatomy.png")
141149
```
142150

143-
---
151+
## Documentação oficial
144152

153+
+++
145154

146-
[Voltar ao notebook principal](00-Tutorial_Python_Sul_2024.md)
155+
Além de tutorials e guias de usuário, a Matplotlib também mantém uma galeria de exemplos bastante completa:
147156

148-
[Ir para o notebook Masked Arrays](03-Exemplo_Masked_Arrays.md)
157+
https://matplotlib.org/stable/gallery/index.html
149158

150-
[Ir para o notebook SVD](04-Exemplo_SVD.md)
159+
```{code-cell} ipython3
160+
from IPython.display import IFrame
161+
```
151162

152-
[Ir para o notebook Queimadas](05-Exemplo_Queimadas.md)
163+
```{code-cell} ipython3
164+
IFrame("https://matplotlib.org/stable/gallery/index.html", width="100%", height=600)
165+
```
153166

167+
```{code-cell} ipython3
168+
169+
```

0 commit comments

Comments
 (0)