我喜欢最近 matpolotlib 更新中 ax.bar_label 的易用性。
我热衷于隐藏低值数据标签以提高最终图中的可读性,以避免标签重叠。
如何在下面的代码中隐藏小于预定义值(这里假设小于 0.025)的标签?
df_plot = pd.crosstab(df['Yr_Lvl_Cd'], df['Achievement_Cd'], normalize='index')
ax = df_plot.plot(kind = 'bar', stacked = True, figsize= (10,12))
for c in ax.containers:
ax.bar_label(c, label_type='center', color = "white")
Run Code Online (Sandbox Code Playgroud)