Seaborn barplot has three parameters.

x, y, hue : names of variables in data or vector data, optional


What is hue? It seems the attribute to plot but why it is called "hue" because when I googled, the result is about color?


Hue - Wikipedia

Hue is one of the main properties (called color appearance parameters) of a color, defined technically (in the CIECAM02 model)


In seaborn, the hue parameter determines which column in the data frame should be used for colour encoding. Using the official document for lmplotprovided an example for this.

import seaborn as sns; sns.set(color_codes=True)
tips = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", data=tips)

enter image description here

Adding `hue="smoker" tells seaborn you want to colour the data points for smoker and non-smoker differently.

>>> g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips)

enter image description here


This is a good question but it seems none of the answers really answered the question.

Simply, in the HSL color system, hue is one of the properties of color which decides what kind of color it looks like, while S and L mean saturation and lightness. Refer to this picture:

enter image description here

Therefore, in seaborn, the hue parameter denotes which column decides the kind of color, i.e. it's red, or green, while the lightness or saturation property may depend on other value columns.


How many different values may an indicator have?

e.g. smoker has two (Yes, No).

I am doing data exploratory analysis on some data that I have and I have observed that when the number of values exceeds 6 then I get the following error:

"IndexError: invalid index to scalar variable."

When it's less there are no errors! Any hint!


Hue does not have any written limit but if we take a very-very large number then it shows index error. here is the example which shows more than 35 values in hue and does not shown any error.

#Taken haberman breast cancer Dataset
#Columns -> Age , year , axillary_nodes , Survival_status

import seaborn as sns  
import matplotlib.pyplot as plt

Image showing the result, have used a list of values for Hue


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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