AttributeError: 'module' object has no attribute 'to_rgb'

16,538

Solution 1

The to_rgb function was added relatively recently to the matplotlib.colors namespace. You probably have an older version of matplotlib installed. Try updating to the latest version of matplotlib.

Solution 2

That's related to the versions of the two tool libraries that ipykernel and matplotlib are not compatible. AttributeError: 'module' object has no attribute 'to_rgba'

Share:
16,538
Mala Pokhrel
Author by

Mala Pokhrel

Updated on June 25, 2022

Comments

  • Mala Pokhrel
    Mala Pokhrel almost 2 years

    I wrote a simple code to form taylor digram using skillmetrics package. I used python version Python 2.7.12. The code is as follows:-

    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy as np
    import skill_metrics as sm
    fire=pd.read_csv('fire.csv')
    PMfire = zip(fire['Date'],fire['PM_fire'],fire['Embassy_PM'])
    #taylor_stats1 = sm.taylor_statistics('PM_fire','Embassy_PM','Date')
    o= {"Data":fire['Embassy_PM'],'Date':fire['Date']}# form date and and embassy datas
    p= {"Data":fire['PM_fire'],'Date':fire['Date']}# form  dictionary containg pm_fire and date
    # Calculate statistics for Taylor diagram
        # The first array element corresponds to the reference series 
        # for the while the second is that for the predicted series.
    taylor_stats1 = sm.taylor_statistics(p,o,'Data')
    sdev = np.array([taylor_stats1['sdev'][0]])# Calculate standard deviation
    crmsd = np.array([taylor_stats1['crmsd'][0]])#Calculate root mean square difference
    ccoef = np.array([taylor_stats1['ccoef'][0]])# Calculate correlation coefficient
    sm.taylor_diagram(sdev,crmsd,ccoef)#form taylor digram
    plt.savefig('taylor.png')
    plt.show()
    

    But, it is giving me error.The error is as follows:-

      File "<ipython-input-2-edf3b67792d8>", line 1, in <module>
        runfile('/home/mala/Downloads/F/taylor_plot.py', wdir='/home/mala/Downloads/F')
    
      File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
        execfile(filename, namespace)
    
      File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
        builtins.execfile(filename, *where)
    
      File "/home/mala/Downloads/F/taylor_plot.py", line 21, in <module>
        sm.taylor_diagram(sdev,crmsd,ccoef)
    
      File "/usr/local/lib/python2.7/dist-packages/skill_metrics/taylor_diagram.py", line 110, in taylor_diagram
        plot_pattern_diagram_markers(X,Y,option)
    
      File "/usr/local/lib/python2.7/dist-packages/skill_metrics/plot_pattern_diagram_markers.py", line 104, in plot_pattern_diagram_markers
        rgba = clr.to_rgb(option['markercolor']) + (alpha,)
    
    AttributeError: 'module' object has no attribute 'to_rgb'
    
  • Mala Pokhrel
    Mala Pokhrel over 6 years
    Thanks the error stopped comming.But now I am getting another error ValueError: shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (1,)
  • ngoldbaum
    ngoldbaum over 6 years
    Please ask a new question. Also in general for Python errors you should always include both the full traceback and the error you see, since the traceback gives the context for where the error comes from.
  • ntg
    ntg over 5 years
    Can anyone that has solved this comment on the required version of matplotlib? I have matplotlib.__version__ == '1.5.1' and get this error for python 2.7
  • ngoldbaum
    ngoldbaum over 5 years
    I think matplotlib 2.0 or newer should have it.
  • TheParam
    TheParam about 5 years
    Please explain your answer so that others will understand more easy way
  • Ganesh Kharad
    Ganesh Kharad about 5 years
    Just run the command------------> sudo pip install --upgrade matplotlib
  • desmond13
    desmond13 about 4 years
    I tried to do pip install --upgrade matplotlib . Now if I check with pip show matplotlib I have Version: 2.2.5 . However, I still have the same error in my Jupiter notebook working with a kernel in a virtualenvironment.
  • desmond13
    desmond13 about 4 years
    I think I found my problem, when I do print matplotlib.__version__ in my jupyter notebook I get the version 1.5.1. So it means that my Jupyter notebook still sees an old version of the library
  • desmond13
    desmond13 about 4 years
    Reading this post: jakevdp.github.io/blog/2017/12/05/… It seems that you should NEVER install any package with sudo pip install