When creating a histogram plot with seaborn, I would like to dynamically put the bar with the lower count to the front. Below is a minimal example where now the blue bar is always in the front, no matter its count. For example, in the second bin, I would like the orange bar to be in the front. Basically, I am looking for something similar to multiple="stack"
, however without adding the columns up. Is that possible?
import numpy as np
import pandas as pd
import seaborn as sns
sns.set()
df_A = pd.DataFrame(np.random.randint(0, 10, 100), columns=["value"])
df_A["label"] = "A"
df_B = pd.DataFrame(np.random.randint(0, 10, 100), columns=["value"])
df_B["label"] = "B"
df = pd.concat([df_A, df_B])
sns.histplot(df, x="value", bins=np.arange(0, 10, 1), hue="label")