我使用skillmetrics包编写了一个简单的代码来形成taylor digram。我使用python版本Python 2.7.12。代码如下: -
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()
但是,它给了我错误。错误如下: -
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'
答案 0 :(得分:6)
to_rgb
函数最近才添加到matplotlib.colors
命名空间。您可能安装了较旧版本的matplotlib。尝试更新到最新版本的matplotlib。
答案 1 :(得分:2)
这与ipykernel和matplotlib不兼容的两个工具库的版本有关。 AttributeError: 'module' object has no attribute 'to_rgba'
答案 2 :(得分:1)
$ sudo pip install --upgrade matplotlib
答案 3 :(得分:0)
尝试将matplotlib和numpy升级到最新版本
sudo pip3 install --upgrade numpy
sudo pip3 install --upgrade matplotlib