A library seaborn that can visualize data in a beautiful graph. Among them, in some methods, if you specify a category in the argument hue, it will color-code each category and draw a graph. However, some methods do not take this hue as an argument. Even in such a case, I will introduce how to color-code each category.
python: 3.7.4 seaborn: 0.9.0
hue First, let's use hue with the countplot method. The data is titanic.
import pandas as pd
import seaborn as sns
data=pd.read_csv("train.csv")
sns.countplot(x='Embarked', data=data, hue='Survived')
In this way, it draws a graph by color-coding each category of'Survived'.
Well, the main subject is from here. For example, the seaborn distplot method does not have a hue argument. (Seaborn.distplot) But sometimes you want to see the distribution for each category. FacetGrid can be used in such cases.
g=sns.FacetGrid(data, hue='Survived', size=5)
g.map(sns.distplot, "Fare")
g.add_legend()
In this way, if you specify it in the hue of the FacetGrid method, you can handle graphs that do not have hue as an argument. (For more information about FacetGrid, please refer to Plot and visualize with Seaborn FacetGrid etc.)
If you want to color-code graphs that do not have hue as an argument, such as distplot and kdeplot, use FacetGrid.
Recommended Posts