Skip to content

Commit f17fb7d

Browse files
author
inoveAlumnos
committed
Update ejemplos
1 parent 836cfec commit f17fb7d

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

ejemplos_clase.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,41 @@ def line_plot():
2929
fig.suptitle('Población histórica mundial', fontsize=16)
3030
ax = fig.add_subplot()
3131

32-
ax.plot(years, poblacion, c='darkgreen')
32+
ax.plot(years, poblacion, c='darkgreen', label='poblacion')
3333
ax.legend()
3434
ax.grid()
3535
plt.show()
36+
print("Fin line plot")
37+
38+
39+
def multi_line_plot():
40+
mes = [3, 4, 5, 6]
41+
gasto_carne = [1650, 2600, 3100, 4000]
42+
gasto_verdura = [2500, 2200, 1800, 600]
43+
44+
# Calcular el gasto total como la suma
45+
# de las listas gasto_carne y gasto_verdura
46+
gasto_total = []
47+
for i in range(len(gasto_carne)):
48+
total = gasto_carne[i] + gasto_verdura[i]
49+
gasto_total.append(total)
50+
51+
# Realizaremos un gráfico "plot" con:
52+
# mes como "x"
53+
# gasto_carne como "y1"
54+
# gasto_cargasto_verdurane como "y2"
55+
# gasto_total como "y3"
56+
fig = plt.figure()
57+
fig.suptitle('Gastos mensuales', fontsize=16)
58+
ax = fig.add_subplot()
59+
60+
ax.plot(mes, gasto_carne, label='carne')
61+
ax.plot(mes, gasto_verdura, label='verdura')
62+
ax.plot(mes, gasto_total, label='total')
63+
ax.legend()
64+
ax.grid()
65+
plt.show()
66+
print("Fin multi line plot")
3667

3768

3869
def scatter_plot():
@@ -49,8 +80,8 @@ def scatter_plot():
4980

5081
fig = plt.figure()
5182
fig.suptitle('Población histórica mundial', fontsize=16)
52-
ax1 = fig.add_subplot(1, 2, 1)
53-
ax2 = fig.add_subplot(1, 2, 2)
83+
ax1 = fig.add_subplot(1, 2, 1) # 1 fila, 2 columnas, axes nº1
84+
ax2 = fig.add_subplot(1, 2, 2) # 1 fila, 2 columnas, axes nº2
5485

5586
# Como los datos no están ordenados por año
5687
# el plot no funcionará bien en este caso
@@ -62,6 +93,7 @@ def scatter_plot():
6293
ax2.legend()
6394
ax2.grid()
6495
plt.show()
96+
print("Fin scatter plot")
6597

6698

6799
def bar_plot():
@@ -81,16 +113,19 @@ def bar_plot():
81113
poblacion.append(int(line['poblacion']))
82114

83115
fig = plt.figure()
84-
fig.suptitle('Población histórica mundial', fontsize=16)
116+
fig.suptitle('Población histórica mundial', fontsize=16, label='poblacion')
85117
ax = fig.add_subplot()
86118

87119
ax.bar(years, poblacion)
88120
ax.legend()
89121
ax.grid()
90122
plt.show()
123+
print("Fin bar plot")
124+
91125

92126
if __name__ == '__main__':
93127
print("Bienvenidos a otra clase de Inove con Python")
94128
line_plot()
129+
multi_line_plot()
95130
scatter_plot()
96131
bar_plot()

0 commit comments

Comments
 (0)