Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Rectangle' object has no property 'norm_hist' - python

I am reviewing the matpoltlib and seaborn packages. I know this question is a little below the level of stack but no one can give me a solid answer about this error. I am using displot to make histograms and the notes are trying to show the difference between it displaying w/ count vs. density. Using the "iris" dataset w/in seaborn the first example is:

[IN]: sns.displot(iris["sepal_length"], kde=False) 
[OUT]: histogram, no curve, count on the y-axis

The next example uses "norm_hist" and is supposed to change the counts to densities and I am getting an error I don't understand?

[IN]: sns.displot(iris["sepal_length"], norm_hist=True, kde=False)
[OUT]: Traceback (most recent call last):

  File "C:\Users\cyrra\OneDrive\Documents\HDS 802 - Programming in Healthcare (Python & R)\Module 7 Python\M7P - MINE.py", line 79, in <module>
    sns.displot(iris["sepal_length"], norm_hist=True, kde=False)

  File "C:\Users\cyrra\anaconda3\lib\site-packages\seaborn\distributions.py", line 2227, in displot
    p.plot_univariate_histogram(**hist_kws)

  File "C:\Users\cyrra\anaconda3\lib\site-packages\seaborn\distributions.py", line 555, in plot_univariate_histogram
    artists = plot_func(

  File "C:\Users\cyrra\anaconda3\lib\site-packages\matplotlib\__init__.py", line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)

  File "C:\Users\cyrra\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 2488, in bar
    r.update(kwargs)

  File "C:\Users\cyrra\anaconda3\lib\site-packages\matplotlib\artist.py", line 996, in update
    raise AttributeError(f"{type(self).__name__!r} object "

AttributeError: 'Rectangle' object has no property 'norm_hist'

Can someone explain this to me? I am looking through the documentation for seaborn and I can't seem to find these options. Were they deprecated? Unfortunately the material provided for my python class in my MS is from 2017 and they won't update it.

Thank you

like image 222
Rachel Cyr Avatar asked Jul 16 '26 02:07

Rachel Cyr


1 Answers

I had this same error and my solution was changing ffn/core.py (it was the first file in the error list, your file is different I see, but same principle norm something must be deprecated?)

from

ax = ser.hist(bins=bins, figsize=figsize, normed=True, **kwargs)

to

ax = ser.hist(bins=bins, figsize=figsize, density=True, **kwargs)

point being: changing the normed to density i.e. here norm_hist to density

like image 85
LakeConstanceCH Avatar answered Jul 18 '26 14:07

LakeConstanceCH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!