import pandas as pd
import matplotlib.pyplot as plt
from dateutil.parser import parse
23 Tipos de gráficas
En esta sección del curso, exploraremos las técnicas visuales disponibles en Matplotlib para representar datos por pares, o Pairwise data.
Desde el gráfico de líneas hasta herramientas como fill_between y stackplot, descubriremos cómo cada tipo de gráfico nos brinda una perspectiva única sobre la relación entre dos variables cuantitativas.
= '../data/Cuernavaca_1dia_comas.csv'
f = pd.read_csv(f,index_col=0,parse_dates=True)
cuerna cuerna.head()
To | Ws | Wd | P | Ig | Ib | Id | |
---|---|---|---|---|---|---|---|
tiempo | |||||||
2012-01-01 00:00:00 | 19.3 | 0.0 | 26 | 87415 | 0 | 0 | 0 |
2012-01-01 01:00:00 | 18.6 | 0.0 | 26 | 87602 | 0 | 0 | 0 |
2012-01-01 02:00:00 | 17.9 | 0.0 | 30 | 87788 | 0 | 0 | 0 |
2012-01-01 03:00:00 | 17.3 | 0.0 | 30 | 87554 | 0 | 0 | 0 |
2012-01-01 04:00:00 | 16.6 | 0.0 | 27 | 87321 | 0 | 0 | 0 |
= plt.subplots()
fig, ax
ax.plot(cuerna.To)'plot') ax.set_title(
Text(0.5, 1.0, 'plot')
= plt.subplots()
fig, ax
ax.scatter(cuerna.index,cuerna.To)'Scatter') ax.set_title(
Text(0.5, 1.0, 'Scatter')
= plt.subplots()
fig, ax # f1 = parse("2012-01-01")
# f2 = f1 + pd.Timedelta("10H")
ax.bar(cuerna.index,cuerna.To)# ax.bar(cuerna.index,cuerna.To,width=1/25)
'Bars')
ax.set_title(
# ax.set_xlim(f1,f2)
Text(0.5, 1.0, 'Bars')
= plt.subplots()
fig, ax
ax.stem(cuerna.To)
= plt.subplots()
fig, ax
ax.fill_between(cuerna.index,cuerna.To.mean(),cuerna.To)'r-') ax.plot(cuerna.To,
= plt.subplots()
fig, ax
ax.stairs(cuerna.To)
Por supuesto hay que escoger cada tipo de gr’afica de acuerdo a los datos y lo que queremos transmitir.
= plt.subplots()
fig, ax
ax.scatter(cuerna.To, cuerna.Ig)
= plt.subplots()
fig, ax
ax.stem(cuerna.To, cuerna.Ig)