![](/img/trans.png)
[英]Plotly AttributeError: 'Figure' object has no attribute 'show'
[英]AttributeError: 'Figure' object has no attribute '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。
您將ax2
分配給未定義plot
方法的figure
對象。 您想改用plt.axes
創建軸
ax2 = plt.axes()
# Instead of ax2 = fig
而不是通過以下方式調用該圖:
ax2 = fig #which just references the figure
嘗試使用gca()
提取軸:
ax2 = fig.gca() #which is used to extract the axes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.