属性错误: 'Figure' 对象没有 'plot' 属性。

17

我的代码

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。

2个回答

16
你将 `ax2` 分配给一个没有定义 `plot` 方法的 `figure` 对象。你想改用 `plt.axes` 创建坐标轴。

你将 ax2 分配给一个没有定义 plot 方法的 figure 对象。你想改用 plt.axes 创建坐标轴。

ax2 = plt.axes()
# Instead of ax2 = fig

13

使用以下方式调用图形:

ax2 = fig #which just references the figure

试着使用gca()来提取轴:

ax2 = fig.gca() #which is used to extract the axes

2
gca代表“获取当前轴”。 - Diego

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接