Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'Figure' object has no attribute 'plot'

My code

import matplotlib.pyplot as plt
plt.style.use("ggplot")
import numpy as np
from mtspec import mtspec
from mtspec.util import _load_mtdata

data = np.loadtxt('262_V01_C00_R000_TEx_BL_4096H.dat')

spec,freq,jackknife,f_statistics,degrees_of_f = mtspec(data=data, delta= 4930.0, time_bandwidth=4 ,number_of_tapers=5, nfft= 4194304, statistics=True)


fig = plt.figure()      
ax2 = fig   
ax2.plot(freq, spec, color='black')
ax2.fill_between(freq, jackknife[:, 0], jackknife[:, 1],color="red", alpha=0.3)
ax2.set_xlim(freq[0], freq[-1])
ax2.set_ylim(0.1E1, 1E5)
ax2.set_xlabel("Frequency $")
ax2.set_ylabel("Power Spectral Density $)")
plt.tight_layout()
plt.show() 

The problem is with the plotting part of my code.What should I change?I am using Python 2.7 on Ubuntu.

like image 994
Richard Rublev Avatar asked Aug 01 '16 14:08

Richard Rublev


2 Answers

You assign ax2 to a figure object which doesn't have a plot method defined. You want to create your axes using plt.axes instead

ax2 = plt.axes()
# Instead of ax2 = fig
like image 126
Suever Avatar answered Oct 21 '22 03:10

Suever


instead of calling the figure with:

ax2 = fig #which just references the figure

try using gca() to extract the axes:

ax2 = fig.gca() #which is used to extract the axes
like image 11
Julio C. Kota Renteria Avatar answered Oct 21 '22 04:10

Julio C. Kota Renteria