Matrix plots en Seaborn —#
0:00 min | Última modificación: Octubre 13, 2021 | [YouTube]
[1]:
from string import ascii_letters
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
[2]:
#
# Heatmap básico
#
df = pd.DataFrame(
np.random.random((10, 10)),
columns=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
)
sns.heatmap(
df,
annot=True,
annot_kws={"size": 7},
)
plt.show()
[3]:
mtcars = pd.read_csv(
"https://raw.githubusercontent.com/jdvelasq/datalabs/master/datasets/mtcars.csv",
)
mtcars = mtcars.set_index('model')
mtcars.head()
[3]:
mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | |
---|---|---|---|---|---|---|---|---|---|---|---|
model | |||||||||||
Mazda RX4 | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.620 | 16.46 | 0 | 1 | 4 | 4 |
Mazda RX4 Wag | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.875 | 17.02 | 0 | 1 | 4 | 4 |
Datsun 710 | 22.8 | 4 | 108.0 | 93 | 3.85 | 2.320 | 18.61 | 1 | 1 | 4 | 1 |
Hornet 4 Drive | 21.4 | 6 | 258.0 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 |
Hornet Sportabout | 18.7 | 8 | 360.0 | 175 | 3.15 | 3.440 | 17.02 | 0 | 0 | 3 | 2 |
[4]:
sns.clustermap(
mtcars,
metric="correlation",
method="single",
cmap="Blues",
standard_scale=1,
)
plt.show()