0

I'm having trouble increasing the size of my bar chart. I am using a template and can't figure out how to increase the size. Currently my bars and labels are overlapping as shown. Image

Any ideas on how to fix?

Template Code:

import matplotlib.pyplot as plt
import numpy as np


labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)

fig.tight_layout()

plt.show()
mcfadX
  • 83
  • 1
  • 4
  • 3
    `fig, ax = plt.subplots(figsize=...)`. – JohanC May 14 '21 at 18:25
  • 2
    When you setup your `subplots` you can pass `figsize=(width, height)`. See the [docs](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html) – Alex May 14 '21 at 18:27

1 Answers1

1

You can use the figsize() method :

plt.figure(figsize=(width, height)) 

So the code which would be useful as per your snippet will be -

fig, ax = plt.subplots(figsize=(width, height))
Amisha Kirti
  • 132
  • 1
  • 9