AttributeError: 'Figure' 对象没有属性 'plot' [英] AttributeError: 'Figure' object has no attribute 'plot'

查看:68
本文介绍了AttributeError: 'Figure' 对象没有属性 'plot'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码

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() 

问题出在我代码的绘图部分.我应该更改什么?我在 Ubuntu 上使用 Python 2.7.

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

推荐答案

你将 ax2 分配给一个没有 plotfigure 的对象代码> 方法定义.您想使用 plt.axes 代替

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

这篇关于AttributeError: 'Figure' 对象没有属性 'plot'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆