[python]How to color code even methods that do not have hue as an argument in Seaborn
Introduction
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.
Environment is python: 3.7.4 seaborn: 0.9.0
What is the argument 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'.
If no argument hue
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 (reference).
Summary
Use FacetGrid if you want to color-code graphs that do not have hue as an argument, such as distplot and kdeplot.
Recent Posts
See AllSummary Data analysis is performed using python. The analysis itself is performed using pandas, and the final results are stored in...
Phenomenon I get a title error when trying to import firestore with raspberry pi. from from firebase_admin import firestore ImportError:...
Overview If you want to do fitting, you can do it with scipy.optimize.leastsq etc. in python. However, when doing fitting, there are many...
Comments