I am trying to order facets in a plot produced by the seaborn
objects interface.
import numpy as np
import seaborn as sns
import seaborn.objects as so
import matplotlib.pyplot as plt
df = sns.load_dataset("iris")
df["species"] = df["species"].astype("category")
df["species"] = df["species"].cat.codes
rng = np.random.default_rng(seed=0)
df["subset"] = rng.choice(['A','B','C'], len(df), replace=True)
fig = plt.figure(figsize=(6.4 * 2.0, 4.8 * 2.0))
_ = (
so.Plot(df, x="sepal_length", y="sepal_width")
.facet(row="species", col="subset")
.add(so.Dot())
.on(fig)
.plot()
)
However, if col_order
or row_order
are passed as parameters to the .facet()
line an "unexpected keyword argument" TypeError
is raised.
_ = (
so.Plot(df, x="sepal_length", y="sepal_width")
.facet(
row="species",
col="subset",
row_order=['A','C','B'],
col_order=[0,2,1]
)
.add(so.Dot())
.on(fig)
.plot()
)
TypeError: Plot.facet() got an unexpected keyword argument 'row_order'
How should facets be ordered when using the seaborn.objects
interface?
Note that this question is very similar to "Seaborn ordering of facets" which is the same question when the plot is generated using seaborn
but not the seaborn.objects
module. The same plot as this question generated without using the seaborn.objects
interface would be as follows...
Ideally, an answer should also work when using the wrap
parameter of facet()
in the seaborn.objects
interface.