Tell us what’s happening:
I’ve spent 2 days trying to complete project with Medical Data Visualizer, but vainly.
I have three fails which I can’t fix:
- Saving catplot (two fails connected with it)
Unfortunately in the course wasn’t provided any information about data visualization. So I am stuck with Catplot, which is always saved as blank plot, though running same code in jupyter lab gives nice plot with data. - Saving heatmap
I am sure I’ve done everything right, but in some cells of heatmap there negative zeroes instead of positive as it is given in tester
Please help
Your code so far
First plot:
# Draw Categorical Plot
def draw_cat_plot():
# Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'.
df_cat = df.melt(value_vars = ['cholesterol', 'gluc', 'smoke', 'alco', 'active', 'overweight'])
# Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly.
df_cat = df.melt(id_vars = ['cardio'], value_vars = ['cholesterol', 'gluc', 'smoke', 'alco', 'active', 'overweight'])
# Draw the catplot with 'sns.catplot()'
fig, ax = plt.subplots()
ax = sns.catplot(x='variable',
col='cardio',
hue = 'value',
data=df_cat,
kind="count")
# Do not modify the next two lines
fig.savefig('catplot.png')
return fig
Second plot
def draw_heat_map():
# Clean the data
df_heat = df[(df['ap_lo'] <= df['ap_hi']) &
(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))]
# Calculate the correlation matrix
corr = df_heat.corr()
# Generate a mask for the upper triangle
mask = np.triu(corr)
# Set up the matplotlib figure
fig, ax = plt.subplots()
# Draw the heatmap with 'sns.heatmap()'
ax = sns.heatmap(corr, annot = True, mask=mask, fmt = '.1f')
# Do not modify the next two lines
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/99.0.4844.84 Safari/537.36
Challenge: Medical Data Visualizer
Link to the challenge: