繁体   English   中英

如何修改seaborn小提琴情节传说

[英]how to modify seaborn violin plot legend

我已经使用seaborn从乐队的DataFrame(下面的df10 )创建了一个简单的小提琴图:

fig, ax = plt.subplots(figsize=(10,4))
ax = sns.violinplot(x='z', y='z_fit', hue='new_col', data=df10, cut=0, palette='Blues', linewidth=1)
ax.set_xlabel('z_sim')
ax.legend()

图例会自动与hue参数的值一起绘制。 使用ax.legend()我只能隐藏使用的列的名称( 'new_col' )。

但是,我想知道是否可以通过以下方式手动修改图例(文本,颜色和形状): 在此处输入图片说明

例:

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time", size=4, aspect=.75)
g = g.map(sns.violinplot, "sex", "total_bill", "smoker", palette={"No": "b", "Yes": "w"}, inner=None, linewidth=1, scale="area", split=True, width=0.75).despine(left=True)
g.fig.get_axes()[0].legend(title= 'smoker',loc='top left',labels=["YES","NO"],edgecolor='red',facecolor='blue',ncol=2)
g.set_axis_labels('lunch','total bill')

有关更多信息,请运行:

help(g.fig.get_axes()[0].legend)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM