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/”, line 26, in test_bar_plot_number_of_bars
actual = len([rect for rect in 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/”, line 13, in test_line_plot_labels
actual =
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:


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

    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