ZEESHAN
ZEESHAN

Reputation: 319

How to remove white-spaces from grouped bar chart Matplotlib

How to remove white spaces from grouped bar chart in Matplotlib. Size of my chart is 3.5x4 inches.

fig= plt.figure(figsize=(3.5,4),dpi=600)

Here is my code

index = np.arange(n_groups)
bar_width = 0.05

rects1 = plt.bar(index, SeriesA_1, bar_width)
rects2 = plt.bar(index + 0.05, SeriesA_2, bar_width)
rects3 = plt.bar(index + 0.10, SeriesA_3, bar_width)
rects4 = plt.bar(index + 0.15, SeriesB_1, bar_width)
rects5 = plt.bar(index + 0.20, SeriesB_2, bar_width)
rects6 = plt.bar(index + 0.25, SeriesB_3, bar_width)
plt.ylim((0,14))

Output: enter image description here

Upvotes: 2

Views: 789

Answers (1)

Ami Tavory
Ami Tavory

Reputation: 76297

  • Since your bar_width is 0.05, and you're plotting 6 items per group, you're using up 0.3 per group.

  • You're plotting at index, that is, jumping 1 per each group.

Try using

plt(0.3 * index + ...

at each place, instead of the current

plt(index + ...

you now have.

Upvotes: 1

Related Questions