因此,当我编译我的python代码(matplot)时,我得到了一个错误,即:
ValueError :每个数据集必须有一种颜色
生成此错误的代码:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import pickle as pkl
from __future__ import division
sns.set(style="darkgrid")
sns.distplot(featureSet[featureSet['label']=='0']['len of url'],color='green',label='Benign URLs')
sns.distplot(featureSet[featureSet['label']=='1']['len of url'],color='red',label='Phishing URLs')
sns.plt.title('Url Length Distribution')
plt.legend(loc='upper right')
plt.xlabel('Length of URL')
sns.plt.show()
发布于 2018-05-28 15:28:06
不要使用sns.plt
。取而代之的是直接使用import matplotlib.pyplot as plt
。
Appart代码应该运行得很好。我创建了以下最小的可运行示例
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.DataFrame({"label" : np.random.randint(2, size=100).astype(str),
"data" : np.random.rayleigh(size=100)})
sns.set(style="darkgrid")
sns.distplot(df[df['label']=='0']['data'],color='green',label='Benign URLs')
sns.distplot(df[df['label']=='1']['data'],color='red',label='Phishing URLs')
plt.title('Url Length Distribution')
plt.legend(loc='upper right')
plt.xlabel('Length of URL')
plt.show()
这将产生以下输出
如果对您无效,请考虑升级matplotlib和seaborn版本。以上代码是使用matplotlib 2.2.2和seaborn 8.1生成的。
发布于 2018-12-12 17:44:47
只要删除颜色属性即可。
删除color='green'
和color = 'red'
,一切都会正常工作。
https://stackoverflow.com/questions/50559775
复制相似问题