我有这样的情节:

问题描述 投票:0回答:1
基本上应该像这样(但没有倒置的Yaxis ...)

enter image description here

这里是一些示例代码生成数据和图...

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 )

enter image description here 即将添加

[::-1]

以逆转颜色顺序。

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 }) palette = sns.color_palette("RdYlGn", n_colors=10)[::-1] 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 ) plt.show()
python matplotlib seaborn
1个回答
0
投票

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.