Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'AttributeError: Unknown property figsize'?

I am trying to plot multiple graphs into 1 using a for loop and I encountered this problem. I tried it for the other loops and it works just fine but I don't know what happened with this one.

The files used are the exchange rates of EUR to USD for the past 2 years and I am trying to plot the date and the price on the graph. If I don't use figsize the graph is too small but it works.

import pandas as pd
import matplotlib.pyplot as plt

file = ['somefile.csv', 'otherfile.csv', 'anotherfile.csv']

for files in file:

    files1 = pd.read_csv ('%s' %files)

    files1.plot (kind='line', x='Date', y='Price', ax=ax, figsize=(15,10))

plt.legend()
plt.show()
like image 545
8126913 Avatar asked Nov 22 '25 14:11

8126913


2 Answers

One way around is using

plt.gcf().set_size_inches(15, 8)

So your code should be

import pandas as pd
import matplotlib.pyplot as plt

file = ['somefile.csv', 'otherfile.csv', 'anotherfile.csv']

for files in file:

    files1 = pd.read_csv ('%s' %files)

    files1.plot (kind='line', x='Date', y='Price', ax=ax)
plt.gcf().set_size_inches(15, 8))

plt.legend()
plt.show()
like image 182
A. Munir Avatar answered Nov 24 '25 03:11

A. Munir


Use the following: Create first the axis object specifying the figure size and then use that object while plotting

fig, ax = plt.subplots(figsize=(15,10))

for files in file:
    files1 = pd.read_csv ('%s' %files)
    files1.plot (kind='line', x='Date', y='Price', ax=ax)
like image 28
Sheldore Avatar answered Nov 24 '25 04:11

Sheldore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!