I have a population pyramid but the x axis on one side is negative, is there a way to rename just the negative x axis so that it is positive?
# Draw Plot
plt.figure(figsize=(13,10), dpi= 80)
group_col = 't1_gender'
order_of_bars = df.agegroup.unique()[::-1]
colors = [plt.cm.Spectral(i/float(len(df[group_col].unique())-1)) for i in range(len(df[group_col].unique()))]
for c, group in zip(colors, df[group_col].unique()):
sns.barplot(x='count', y='agegroup', data=df.loc[df[group_col]==group, :], order=order_of_bars, color=c, label=group)
# Decorations
plt.xlabel("Number of calls")
plt.ylabel("Age group")
plt.yticks(fontsize=12)
plt.title("", fontsize=22)
plt.legend()
plt.savefig('images/figure2.png', dpi=300, facecolor=ax.get_facecolor(), transparent=True, pad_inches=0.0)
plt.show()
A possible solution is to get the current ticks using get_xticks()
and then use the np.abs
function to force the tick labels to be positive:
xticks = plt.gca().get_xticks().astype(np.int)
plt.xticks(xticks, labels=np.abs(xticks));
(add the code to the #decoration section)