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

24,408

Solution 1

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

Solution 2

According to the documentation, displot indeed does not have this parameter.

your are confused with the deprecated distplot function (here) that has it.

Share:
24,408

Related videos on Youtube

Rachel Cyr
Author by

Rachel Cyr

Updated on July 05, 2022

Comments

  • Rachel Cyr
    Rachel Cyr almost 2 years

    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

  • mwaskom
    mwaskom over 3 years
    Correct that displot does not have that exact parameter, but it exposes the same functionality (with additional forms of normalization) through the stat parameter. So displot(..., stat="density") is equivalent to distplot(..., norm_hist=True).
  • mwaskom
    mwaskom over 3 years
    (To be more clear, it is histplot that has a stat parameter; it gets passed through as part of the kwargs if you supply it to displot.