2

So, I got an error when I compile my python code (matplot) which is :

ValueError : color kwarg must have one color per dataset

The code which generates this error :

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()
5

2 Answers 2

2

Don't use sns.plt. Instead import matplotlib.pyplot as plt and use it directly.

Appart the code should run fine. I created the following minimal runnable example

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()

which produces the following output

enter image description here

If it does not work for you, consider upgrading your matplotlib and seaborn version. The above is produced with matplotlib 2.2.2 and seaborn 8.1.

3
  • I am having error on another function. That's why it still got error. But anyways thanks so I know where the problem lies in. May 29, 2018 at 16:02
  • Why can't I use seaborn library? Jan 16, 2019 at 20:11
  • The example does use seaborn. Jan 16, 2019 at 21:24
-2

Just delet color atribute.

Delete color='green' and color = 'red' and everything will work ok.

1
  • And if the user wants colors?
    – Info5ek
    Feb 24, 2019 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.