Medical Data Analyser - 2 errors

I keep getting this error. I would appreciate any help.

`Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-1/test_module.py”, line 26, in test_bar_plot_number_of_bars
actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)])
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get_children’

======================================================================
ERROR: test_line_plot_labels (test_module.CatPlotTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-1/test_module.py”, line 13, in test_line_plot_labels
actual = self.ax.get_xlabel()
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get_xlabel’


Ran 4 tests in 14.116s`

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Medical Data Visualizer

Link to the challenge:

Hey!

I remember I faced this same problem, but I’m really not sure how I solved it.

What is your code for the '# Draw the catplot with ‘sns.catplot()’ section?

Thank you for your response. Below is the code you requested to see.

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 = pd.melt(df, id_vars = ['cardio'], value_vars = ['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'])

    # Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the collumns for the catplot to work correctly.
    df_cat['total'] = 1
    df_cat = df_cat.groupby(['cardio', 'variable', 'value'], as_index = False).count()

    # Draw the catplot with 'sns.catplot()'
    fig = sns.catplot(y = 'total', x = 'variable', data = df_cat, kind = 'bar', col = 'cardio', hue ='value')


    # Do not modify the next two lines

    fig.savefig('catplot.png')
    return fig

Try doing that (adding .fig at the end of your sns.catplot to effectively return a fig object).

Wow! Thank you so much! It worked fine.

1 Like

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