i have a plot like this:
now I want to inverse the order of the stacked bars without changing the color-value-mapping: low value->red, high_value-> green. in short: lowest bar is red with value 1 and the top par is green with value 10.
basically it should look like this (but without the inverted yaxis...)
here is some sample code to generate the data and the plot...
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
#dummy data
relative_amount_bad_scores = np.random.rand(1000)
aggregated_score = np.random.choice(
np.arange(1, 11), 1000, p=[0.05, 0.05, 0.1, 0.1, 0.15, 0.15, 0.15, 0.1, 0.1, 0.05]
)
df_dummy = pd.DataFrame({
"relative_amount_of_bad_scores": relative_amount_bad_scores,
"aggregated_score": aggregated_score
})
# Plot
palette = sns.color_palette("RdYlGn", as_cmap=True)
fig, ax = plt.subplots(figsize=(15, 15))
sns.histplot(
data=df_dummy.sort_values('aggregated_score', ascending = True),
x="relative_amount_of_bad_scores",
hue="aggregated_score",
multiple="fill",
ax=ax,
binwidth=0.1,
palette = palette
)