Use a common x-axis and convert one of the datasets to contain negative values.
y = ['{} to {} years'.format(i, i+4) for i in range(0, 90, 4)]
d_1 = np.random.randint(0, 150, 23)
d_2 = -1 * d_1
Then plot:
fig, ax = plt.subplots()
ax.bar(y, d_1)
ax.bar(y, d_2)
# Formatting x labels
plt.xticks(rotation=90)
plt.tight_layout()
# Use absolute value for y-ticks
ticks = ax.get_yticks()
ax.set_yticklabels([int(abs(tick)) for tick in ticks])
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.