如何在 seaborn 中的条带图中添加多个标记?
How do I add multiple markers to a stripplot in seaborn?
我想知道如何在同一个带状图中获得多个标记。
tips = sns.load_dataset("tips")
coldict={'Sun':'red','Thur':'blue','Sat':'yellow','Fri':'green'}
markdict={'Sun':'x','Thur':'o','Sat':'o','Fri':'o'}
tips['color']=tips.day.apply(lambda x: coldict[x])
tips['marker']=tips.day.apply(lambda x: markdict[x])
m=sns.stripplot('size','total_bill',hue='color',\
marker='marker',data=tips, jitter=0.1, palette="Set1",\
split=True,linewidth=2,edgecolor="gray")
这似乎不起作用,因为标记只接受一个值。
我还希望将相应的 'Sun' 值设置为透明的红色三角形。知道如何实现吗?
谢谢。
编辑:
所以一个更好的方法是声明一个 my_ax = plt.axes()
并将 my_ax 传递给每个 stripplot(ax=my_ax)。我相信这是应该的方式。
注意这有点老套,但你开始吧:
import sns
tips = sns.load_dataset("tips")
plt.clf()
thu_fri_sat = tips[(tips['day']=='Thur') | (tips['day']=='Fri') | (tips['day']=='Sat')]
colors = ['blue','yellow','green','red']
m = sns.stripplot('size','total_bill',hue='day',
marker='o',data=thu_fri_sat, jitter=0.1,
palette=sns.xkcd_palette(colors),
split=True,linewidth=2,edgecolor="gray")
sun = tips[tips['day']=='Sun']
n = sns.stripplot('size','total_bill',color='red',hue='day',alpha='0.5',
marker='^',data=sun, jitter=0.1,
split=True,linewidth=0)
handles, labels = n.get_legend_handles_labels()
n.legend(handles[:4], labels[:4])
plt.savefig('/path/to/yourfile.png')
Lmplot 是你的朋友!但是,不可能添加倍数:/ [或者至少我还没有弄明白]
enter image description here
我想知道如何在同一个带状图中获得多个标记。
tips = sns.load_dataset("tips")
coldict={'Sun':'red','Thur':'blue','Sat':'yellow','Fri':'green'}
markdict={'Sun':'x','Thur':'o','Sat':'o','Fri':'o'}
tips['color']=tips.day.apply(lambda x: coldict[x])
tips['marker']=tips.day.apply(lambda x: markdict[x])
m=sns.stripplot('size','total_bill',hue='color',\
marker='marker',data=tips, jitter=0.1, palette="Set1",\
split=True,linewidth=2,edgecolor="gray")
这似乎不起作用,因为标记只接受一个值。
我还希望将相应的 'Sun' 值设置为透明的红色三角形。知道如何实现吗?
谢谢。
编辑: 所以一个更好的方法是声明一个 my_ax = plt.axes() 并将 my_ax 传递给每个 stripplot(ax=my_ax)。我相信这是应该的方式。
注意这有点老套,但你开始吧:
import sns
tips = sns.load_dataset("tips")
plt.clf()
thu_fri_sat = tips[(tips['day']=='Thur') | (tips['day']=='Fri') | (tips['day']=='Sat')]
colors = ['blue','yellow','green','red']
m = sns.stripplot('size','total_bill',hue='day',
marker='o',data=thu_fri_sat, jitter=0.1,
palette=sns.xkcd_palette(colors),
split=True,linewidth=2,edgecolor="gray")
sun = tips[tips['day']=='Sun']
n = sns.stripplot('size','total_bill',color='red',hue='day',alpha='0.5',
marker='^',data=sun, jitter=0.1,
split=True,linewidth=0)
handles, labels = n.get_legend_handles_labels()
n.legend(handles[:4], labels[:4])
plt.savefig('/path/to/yourfile.png')
Lmplot 是你的朋友!但是,不可能添加倍数:/ [或者至少我还没有弄明白]
enter image description here