Tell us what’s happening:
My heat map doesn’t exacly match the expected heat map
Your code so far
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
1
df = pd.read_csv(‘medical_examination.csv’)
2
df[‘overweight’] = (df[‘weight’]/((df[‘height’]/100)**2)> 25).astype(int)
3
df[‘cholesterol’] = (df[‘cholesterol’]> 1).astype(int)
df[‘gluc’] = (df[‘gluc’]> 1).astype(int)
4
def draw_cat_plot():
# 5
df_cat = pd.melt(df, id_vars=[‘cardio’],
value_vars=[‘cholesterol’, ‘gluc’, ‘smoke’, ‘alco’, ‘active’, ‘overweight’],
var_name=‘variable’,
value_name=‘value’)
# 6
df_cat = df_cat.groupby(['cardio', 'variable', 'value']).size().reset_index(name='count')
# 7
g =sns.catplot(x='variable', hue='value', col='cardio', data=df_cat, kind='count')
g.set_axis_labels("variable", "total")
# 8
fig = g.figure
# 9
fig.savefig('catplot.png')
return fig
10
def draw_heat_map():
# 11
df_heat =df[
(df['height'] >= df['height'].quantile(0.025)) &
(df['height'] <= df['height'].quantile(0.975)) &
(df['weight'] >= df['weight'].quantile(0.025)) &
(df['weight'] <= df['weight'].quantile(0.975))
]
# 12
corr = df_heat.corr()
# 13
mask = np.triu(np.ones_like(corr, dtype=bool))
# 14
fig, ax = plt.subplots(figsize=(10, 8))
# 15
sns.heatmap(corr, mask=mask, annot=True, cmap='magma', fmt='.1f',
square=True, linewidths=0.5, cbar_kws={"shrink": .8}, ax=ax)
# 16
fig.savefig('heatmap.png')
return fig
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Medical Data Visualizer