How to fix "AttributeError: 'function' object has no attribute 'rcParams'"

3.2k Views Asked by At

I've been plotting the graph with the below code just fine as the Index as the X-axis. However, now I am trying to make the 'time' column in my data the X-axis and plot that way but I've run into an issue of getting out a blank plot.

Read online and saw others found "plt.plot.rcParams['agg.path.chunksize'] = 20000" useful for this issue. However, now I am running into this error: AttributeError: 'function' object has no attribute 'rcParams'

Can you please help?

SAMPLE DATA:

crew    experiment  time    seat    eeg_fp1 eeg_f7  eeg_f8  eeg_t4  eeg_t6  eeg_t5  ... eeg_c4  eeg_p4  eeg_poz eeg_c3  eeg_cz  eeg_o2  ecg r   gsr event
0   1   CA  0.011719    1   -5.28545    26.775801   -9.527310   -12.793200  16.717800   33.737499   ... 37.368999   17.437599   19.201900   20.596800   -3.951150   14.507600   -4520.0 817.705994  388.829987  A
1   1   CA  0.015625    1   -2.42842    28.430901   -9.323510   -3.757230   15.969300   30.443600   ... 31.170799   19.399700   19.689501   21.354700   1.332120    17.750200   -4520.0 817.705994  388.829987  A
2   1   CA  0.019531    1   10.67150    30.420200   15.350700   24.724001   16.143101   32.142799   ... -12.012600  19.396299   23.171700   22.407600   1.537860    22.247000   -4520.0 817.705994  388.829987  A
3   1   CA  0.023438    1   11.45250    25.609800   2.433080    12.412500   20.533300   31.494101   ... 18.574100   23.156401   22.641199   19.336700   2.544920    18.998600   -4520.0 817.705994  388.829987  A
4   1   CA  0.027344    1   7.28321     25.942600   0.113564    5.748000    19.833599   28.753599   ... 6.555440    22.754700   22.670300   20.293200   1.699620    22.812799   -4520.0 817.705994  388.829987  A
5   1   CA  0.031250    1   6.06746     23.128300   8.645660    14.380800   16.055500   26.925200   ... -9.289120   21.440599   23.253700   19.069599   -0.765018   26.451900   -4520.0 817.705994  388.829987  A
6   1   CA  0.035156    1   -1.37602    20.972000   3.754160    13.766700   18.122000   29.391199   ... -0.604736   20.993401   21.556200   17.327299   1.465000    21.289301   -4520.0 817.705994  388.829987  A
7   1   CA  0.039062    1   1.54787     18.398100   -9.113150   -1.033160   22.627001   32.816601   ... 17.483601   22.912600   23.187000   18.462700   0.299232    23.691500   -4520.0 817.705994  388.829987  A
8   1   CA  0.042969    1   -7.78946    12.210700   -8.953760   1.091740    28.526501   35.267200   ... 16.681101   28.779600   28.382099   20.697300   -6.620750   31.672701   -4520.0 817.705994  388.829987  A
9   1   CA  0.046875    1   -11.17750   18.235901   -1.035220   4.751110    25.983801   30.499100   ... 0.489098    21.937500   21.629299   19.525999   -5.186040   21.618700   -4520.0 817.705994  388.829987  A
10 rows × 28 columns

​


MY CODE

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

df = pd.read_csv('train.csv', index_col='time')
df.sort_values(by='time')

plt.plot(df['ecg'], label='data', color="orange")

plt.plot.rcParams['agg.path.chunksize'] = 20000


plt.title("ECG Data")
plt.grid()
plt.legend()
plt.tight_layout()
plt.show()
1

There are 1 best solutions below

2
On

From here it looks like the syntax is:

mpl.rcParams['lines.color'] = 'r'

where mpl is

import matplotlib as mpl

It does appear that 'agg.path.chunksize' is a valid option though so I would recommend trying:

import matplotlib as mpl
mpl.rcParams['agg.path.chunksize'] = 20000

@ALollz believes that the error could just be the .plot and perhaps a simpler solution would be to just change

plt.plot.rcParams['agg.path.chunksize'] = 20000

to

plt.rcParams['agg.path.chunksize'] = 20000