# Can't complete project

**URL:** <https://forum.freecodecamp.org/t/cant-complete-project/503036>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [March 31, 2022, 7:22pm UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036 "2022-03-31T19:22:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![henkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/henkey/32/134702_2.png) [@henkey](https://forum.freecodecamp.org/u/henkey)\
**Post date:** [March 31, 2022, 7:22pm UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/1 "2022-03-31T19:22:37Z")

</div>

**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:

1. 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.
2. 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:

```auto
# 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

```auto
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:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/data-analysis-with-python/data-analysis-with-python-projects/medical-data-visualizer)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [March 31, 2022, 7:23pm UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/2 "2022-03-31T19:23:19Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [March 31, 2022, 8:04pm UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/3 "2022-03-31T20:04:50Z")

</div>

For a start, why even call plt.subplots() if you are not doing anything with it?  
Then please concern yourself with the documentation on how to use the two together.

---

<div class="post-metadata">

**Author:** ![henkey](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/henkey/32/134702_2.png) [@henkey](https://forum.freecodecamp.org/u/henkey)\
**Post date:** [April 1, 2022, 6:32am UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/4 "2022-04-01T06:32:27Z")

</div>

Rhe reason why I call plt.subplots() is that it is the only fubction, whuch gives ‘fig’ and ‘ax’ output. In a blank project there is line for the second plot like

```auto
fig, ax = None

```

I found that these two variables are commonly used with plt.subplots. The second plot is saved without errors. Before that my first plot was difined as just:

```auto
fig = sns.catplot(x='variable',
                col='cardio',
                hue = 'value',
                data=df_cat,
                kind="count")

```

And it returned two errors while testing. Firstly it doesn’t have method .get\_children, which is used in testing module (error1), secondly it doesn’t have method get\_xlabel whixh is also used.  
So I decided to change the first one like the second. Now I have no errors, but plot is never saved.

I’ve read the documentation and stackoverflow and a lot of other sites, but couldn’t find the right way to complete this task. I am novice and studying Python for a couple of weeks, surely I could miss something. But right now I have no idea what to do and where to find answers.

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [April 1, 2022, 11:46am UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/5 "2022-04-01T11:46:58Z")

</div>

> [@henkey](#):
>
> So I decided to change the first one like the second.

Those are not random variables which you can just change…  
The error happens because seaborn returns a facetgrid object, but the test wants the actual matplot figure wich is saved in the `.figure` attribute of the facetgrid 😉

You don’t get errors becauce you save the plot in a local variable that’s not returned. What is returned is the empty figure you created, which is still empty.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 30, 2022, 11:47pm UTC](https://forum.freecodecamp.org/t/cant-complete-project/503036/6 "2022-09-30T23:47:09Z")

</div>

Closed on September 30, 2022, 11:47pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
