我正在尝试组合两段代码,以使我的地块图例位于主图之外,并且只有一组标签。 [请参见下图。]现在,我可以删除双图例,也可以将其移到外面。我认为我需要更好地了解如何将所有图例信息合并到一个对ax.legend()
的调用中。
ax = sns.boxplot(x="surface_proteins", y="total_peaks", hue="pattern_geom",
data=dfAnalysis, palette="Set3")
sns.swarmplot(x="surface_proteins", y="total_peaks", hue="pattern_geom",
data=dfAnalysis, color = ".25", dodge=True)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[:2], labels[:2])
ax.set_title('Total Number of Peaks Per Neuron')
ax.set_ylabel('Number of Peaks')
ax.set_xlabel('Surface Proteins')
ax.legend(title='Pattern Geometry')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.savefig('PFP_PPN.'+timestamp+'.png', bbox_inches='tight', dpi = 300, format = "png")
pdf.savefig(bbox_inches='tight')
plt.close()
Swarmplot叠加在Boxplot上;结果按类别显示: