[Bug] - Visualizing Categorical Data - Introduction to Bar Charts - Step 2 - Unknown Property Density Error. See below for fix

Hi,

I’ve been going through the Visualizing Categorical Data - Introduction to Bar Charts URL:
https://www.codecademy.com/paths/data-science/tracks/dscp-summary-statistics/modules/dacp-visualizing-categorical-data/lessons/bar-charts-and-pie-charts-lesson/exercises/intro-bar-charts

I have completed the required code to progress to the next step and it is coming up with an ‘Unknown Density Error’ and will not let me proceed to the next stage.

To rule out my own solution as the cause (You never know?!?) I tried the solution code provided and this again resulted in the error.

I am using the platform on Google Chrome (latest build)

The traceback error is as follows:

Traceback (most recent call last):
File “plot.py”, line 20, in
sns.distplot(heroes_data_cleaned[“Height”])
File “/usr/local/lib/python3.6/dist-packages/seaborn/distributions.py”, line 2619, in distplot
color=hist_color, **hist_kws)
File “/usr/local/lib/python3.6/dist-packages/matplotlib/init.py”, line 1898, in inner
return func(ax, *args, **kwargs)
File “/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_axes.py”, line 6389, in hist
p.update(kwargs)
File “/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py”, line 885, in update
for k, v in props.items()]
File “/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py”, line 885, in
for k, v in props.items()]
File “/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py”, line 878, in _update_property
raise AttributeError(‘Unknown property %s’ % k)
AttributeError: Unknown property density

Thanks,
Martin

Can you post the code please? What step is this in the lesson?

I’m wondering if you’re using this attribute: density=True and it’s throwing an error?

That attr is from an older version of python was replaced in the plt.hist chart with the normed = True argument.

Its step-2 - Like I said the solution code also throws the error.

import codecademylib3
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

add in your answers here!

left_plot = “Bar Chart”
right_plot = “Histogram”
heroes_data = pd.read_csv(“heroes_information.csv”)

line of code used to clean up messy data

heroes_data_cleaned = heroes_data[heroes_data.Alignment != “-”]

code for left plot

plt.subplot(1, 2, 1)
sns.countplot(heroes_data_cleaned[“Alignment”])

code for right plot

plt.subplot(1, 2, 2)
sns.distplot(heroes_data_cleaned[“Height”])
plt.xlim(0,500)
plt.show()

Mine passes (checkmark) and am able to proceed to step 3. BUT, I get that error message as well. I think it has to do with some older backend files for this step. I’ll report it now.
If I remember correctly, this is part of an older lesson and maybe the backend code/tests are older and haven’t been updated.

Update: I just reported it. Will let you know of any updates.

@martsmith187 Okay, it should be fixed.

sns.distplot() was deprecated in the latest version of seaborn. So, that code no longer works. If you change sns.displot() to sns.histplot() it will run. (I just changed it and it worked.

sns.histplot(heroes_data_cleaned["Height"], kde=False)

1 Like

Awesome thanks - That worked.
Thanks again for the assistance.

1 Like