파이썬

[matplotlib] seaborn facetgrid에서 순서 바꾸기

mcdn 2023. 4. 24. 16:59
반응형

 

FacetGrid에서 순서 바꾸기

 

row_order col_order 파라미터를 활용한다. 

 

g = sns.FacetGrid(df, col="species", col_order=[0,2,1],row="subset",row_order=['C','B','A'])

 

from sklearn.datasets import load_iris
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

data = load_iris()
df = pd.DataFrame(data.data, columns=['sepal.length','sepal.width','petal.length','petal.width'])
df['species'] = data.target
df['subset'] = np.random.choice(['A','B','C'],150,replace=True)

g = sns.FacetGrid(df, col="species", col_order=[0,2,1],row="subset",row_order=['C','B','A'])
g = g.map(plt.scatter, "sepal.length", "sepal.width")

 

Reference: 

https://stackoverflow.com/questions/61541776/seaborn-ordering-of-facets

반응형