Mala Pokhrel
Mala Pokhrel

Reputation: 143

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

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'

Upvotes: 4

Views: 17735

Answers (4)

Manasa Mudigonda
Manasa Mudigonda

Reputation: 105

Try upgrading matplotlib and numpy to the latest version

sudo pip3 install --upgrade numpy
sudo pip3 install --upgrade matplotlib

Upvotes: -1

Ganesh Kharad
Ganesh Kharad

Reputation: 341

Just run the command below it will solve the issue

$ sudo pip install --upgrade matplotlib

Upvotes: -2

PandaO
PandaO

Reputation: 86

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'

Upvotes: 3

ngoldbaum
ngoldbaum

Reputation: 5580

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.

Upvotes: 7

Related Questions