@@ -29,10 +29,41 @@ def line_plot():
29
29
fig .suptitle ('Población histórica mundial' , fontsize = 16 )
30
30
ax = fig .add_subplot ()
31
31
32
- ax .plot (years , poblacion , c = 'darkgreen' )
32
+ ax .plot (years , poblacion , c = 'darkgreen' , label = 'poblacion' )
33
33
ax .legend ()
34
34
ax .grid ()
35
35
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" )
36
67
37
68
38
69
def scatter_plot ():
@@ -49,8 +80,8 @@ def scatter_plot():
49
80
50
81
fig = plt .figure ()
51
82
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
54
85
55
86
# Como los datos no están ordenados por año
56
87
# el plot no funcionará bien en este caso
@@ -62,6 +93,7 @@ def scatter_plot():
62
93
ax2 .legend ()
63
94
ax2 .grid ()
64
95
plt .show ()
96
+ print ("Fin scatter plot" )
65
97
66
98
67
99
def bar_plot ():
@@ -81,16 +113,19 @@ def bar_plot():
81
113
poblacion .append (int (line ['poblacion' ]))
82
114
83
115
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' )
85
117
ax = fig .add_subplot ()
86
118
87
119
ax .bar (years , poblacion )
88
120
ax .legend ()
89
121
ax .grid ()
90
122
plt .show ()
123
+ print ("Fin bar plot" )
124
+
91
125
92
126
if __name__ == '__main__' :
93
127
print ("Bienvenidos a otra clase de Inove con Python" )
94
128
line_plot ()
129
+ multi_line_plot ()
95
130
scatter_plot ()
96
131
bar_plot ()
0 commit comments