在Python中使用数据框和此代码,我能够创建一个图:
g = sns.lmplot('credibility', 'percentWatched', data=data, hue = 'millennial', markers = ["+", "."], x_jitter = True, y_jitter = True, size=5)
g.set(xlabel = 'Credibility Ranking\n ? Low High ?', ylabel = 'Percent of Video Watched [%]')
Run Code Online (Sandbox Code Playgroud)
但是有传说说"+ 0"和".1"对读者来说并不是很有帮助.如何编辑图例的标签?理想情况下,它不是说"千禧一代",而是说"一代"和"+千禧一代"."老一代"
我在下面的代码中创建了 2 个图。JobDomain我在列中有类别值
下面的代码为上述类别生成 2 个图,每个图具有不同的颜色。我需要保持这 3 个类别的两个图具有相同的颜色。
colors = ["#F28E2B", "#4E79A7","#79706E"]
edu = (df.groupby(['JobDomain'])['sal']
.value_counts(normalize=True)
.rename('Percentage')
.mul(100)
.reset_index()
.sort_values('sal'))
coding = (df.groupby(['JobDomain'])['sal2']
.value_counts(normalize=True)
.rename('Percentage')
.mul(100)
.reset_index()
.sort_values('sal2'))
fig, axs = plt.subplots(ncols=2,figsize=(20, 6),sharey=True)
plt.subplots_adjust(wspace=0.4)
p=sns.barplot(x="sal",y="Percentage",hue="JobDomain",data=edu,
ax=axs[0],palette=sns.color_palette(colors))
q=sns.barplot(x="sal2",y="Percentage",hue="JobDomain",data=coding,
ax=axs[1],palette=sns.color_palette(colors))
Run Code Online (Sandbox Code Playgroud)