我有个问题,据我所知还没有解决。你知道吗
我需要格式化我的轴和数据点为我的Seaborn/Matplotlib图是动态的。下面是我想要实现的一个例子(通过Keynote完成,我使用了一个对数比例来更清楚地说明这一点)。你知道吗
最好的办法是什么?我看到答案的格式要么是Ks要么是Ms,但从来没有两者都是。我错过什么了吗?你知道吗
现在我正在使用FuncFormatter选项
if options.get('ctype') == 'number':
df = df.loc[df[ycat2] >= 1].copy()
plt.figure(figsize=(14,7.5))
plot = sns.barplot(xcat1, ycat2, data=df, color='#00c6ff', saturation=1, ci=None)
sns.despine(top = True, right = True, left=True)
#plot.set_title('Instagram - Engagement Rate', fontweight='bold',y=1.04, loc = 'left', fontsize=12)
plot.yaxis.grid(True)
plot.yaxis.get_major_ticks()[0].label1.set_visible(False)
plot.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:,}'.format(int(y))))
plot.set_xlabel('')
plot.set_ylabel('')
plot.tick_params(axis="x", labelsize=13)
plot.tick_params(axis="y", labelsize=13)
for i, bar in enumerate(plot.patches):
h = bar.get_height()
plot.text(
i,
h,
'{:,}'.format(int(h)),
ha='center',
va='bottom',
fontweight='heavy',
fontsize=12.5)
return plot.figure
Matplotlib有一个Engineering formatter专门用于此目的。您可以使用它格式化轴(使用}
set_major_formatter()
)或格式化任何数字,使用^{相关问题 更多 >
编程相关推荐