Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to decrease the space between grouped bar-subplots in matplotlib?

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

a_means, a_CI = (70, 60), (2.7, 1.9)
b_means, b_CI = (85, 83), (2.6, 1.2)
c_means, c_CI = (66, 64), (3.5, 1.8)

ind = np.arange(2)
width = 0.35

fig, ax = plt.subplots(figsize=(10, 4), facecolor='w', edgecolor='k')
rects1 = ax.bar(ind - 2*width/4, a_means, width/4, yerr=a_CI, label='a')
rects2 = ax.bar(ind - width/4, b_means, width/4, yerr=b_CI, label='b')
rects3 = ax.bar(ind, c_means, width/4, yerr=c_CI, label='c')

ax.set_xticks(ind)
ax.set_ylim([50, 100])
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1),
          fancybox=True, shadow=True, ncol=3)

plt.show()

This is what I get:
old

This is what I want to get:
new

Any ideas how I can achieve this? Thank you in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can change ind = np.arange(2) to something like:

ind = np.arange(2) / 2.5

Play with the number, then you can eventually change tick labels if they don’t satisfy your needs.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading