我在轴上有经验组的条形图顶部制作了一个Seaborn条形图,根据数据帧中的两种不同条件(目标存在或目标不存在)使用以下代码进行分组:
IZ_colors = ['#E1F3DC','#56B567']
ax1 = sns.barplot(data=IZ_df, x='Group', y='Time in IZ (%)', hue='Condition',
order=['Std_Ctrl','ELS_Ctrl','Std_CSDS','ELS_CSDS'], hue_order=['Empty','Aggressor'],
palette=IZ_colors)
hatches = ['','//']
# Loop over the bars
for bars, hatch in zip(ax1.containers, hatches):
# Set a different hatch for each group of bars
for bar in bars:
bar.set_hatch(hatch)
sns.stripplot(data=IZ_df ,x='Group', y='Time in IZ (%)', hue='Condition', dodge=True,
order=['Std_Ctrl','ELS_Ctrl','Std_CSDS','ELS_CSDS'], hue_order=['Empty','Aggressor'],
palette=IZ_colors, marker='o', size=7, edgecolor='#373737', linewidth=1, color='black',)
plt.legend(bbox_to_anchor=(1.35, 0.7))
但是,我希望条带图的标记按性别(而不是现在的情况)着色,这是数据框中的另一列。我仍然希望它们按色调和条件分组。这可能吗
您可以创建两个
stripplots
,每个性别一个,并将它们绘制为相同的点。图例的双条目可以通过get_legend_handles_labels()
删除,并获取句柄和标签的子集下面是一个使用泰坦尼克号数据集的示例:
相关问题 更多 >
编程相关推荐