1

I've found other topics similar to this, but I'm finding anything that works specifically for me, so I'm wondering what I'm doing wrong.

I've got the following code:

# Plot weather vs. # of accidents on grouped-bar-chart for each year
data_chart = dataset2.plot.bar()
data_chart.set_xlabel('Weather Condition')
data_chart.set_ylabel('No. of Accidents')
data_chart.set_title('Annual Number of Accidents per Weather Condition')

I've tried using the two following bits of code to increase the size of my chart:

data_chart.plot(figsize=(10,5))

plt.figure(figsize=[10,5])

but neither of them have worked.

Thank you for your help!

5
  • 1
    fig, ax = plt.subplots(figsize=(10,5)), dataset2.plot.bar(ax=ax). Commented Apr 15, 2020 at 21:40
  • Calling plt.figure(figsize=[10,5]) after you created the plot just creates a new plot. Commented Apr 15, 2020 at 21:59
  • 1
    Does this answer your question? Inconsistency when setting figure size using pandas plot method Commented Apr 15, 2020 at 22:01
  • Thanks, but I just get NameError: name 'ax' is not defined. Do I need to import something special to use ax? Commented Apr 15, 2020 at 22:02
  • Please see my answer and check if it works. If it doesn't let me know I will help. Commented Apr 16, 2020 at 0:39

1 Answer 1

2

Please try

import matplotlib .pyplot as plt
plt.rcParams["figure.figsize"] = (10,5)
data_chart = dataset2.plot.bar()
data_chart.set_xlabel('Weather Condition')
data_chart.set_ylabel('No. of Accidents')
data_chart.set_title('Annual Number of Accidents per Weather Condition')
plt.show()

Matplot lib defaults **to width, height in inches=[6.4, 4.8]**. set as rcParams["figure.figsize"] = [6.4, 4.8]. So Change them to (10,5)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.