首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ValueError:“每个数据集必须有一种颜色”matplotlib

ValueError:“每个数据集必须有一种颜色”matplotlib
EN

Stack Overflow用户
提问于 2018-05-28 13:41:39
回答 2查看 11.1K关注 0票数 2

因此,当我编译我的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()
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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生成的。

票数 2
EN

Stack Overflow用户

发布于 2018-12-12 17:44:47

只要删除颜色属性即可。

删除color='green'color = 'red',一切都会正常工作。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50559775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档