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

时间:2019-04-21 16:24:27

标签: python matplotlib plot seaborn violin-plot

我已经使用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')。

但是,我想知道是否可以通过以下方式手动修改图例(文本,颜色和形状): enter image description here

1 个答案:

答案 0 :(得分:0)

示例:

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)