python-3.x - gwpy 包给出错误 - AttributeError:模块“matplotlib.pyplot”在 Google Colab 中没有属性“FigureManagerBase”
问题描述
在 Google Colab gwpy包中给出错误 -
AttributeError:模块“matplotlib.pyplot”没有属性“FigureManagerBase”
(但是,同样的代码在本地机器上运行良好)。
我已经尝试过完全卸载,然后使用以下命令重新安装gwpy fresh 并重新启动(重置)Colab 的机器。但错误仍然存在。
!pip install --upgrade --force-reinstall --no-deps gwpy
# And also the below ones
!pip install gwosc
!pip install dqsegdb2
!pip install ligotimegps
我的代码,使用gwpy包如下
import pandas as pd
import seaborn as sns
from scipy import signal
from gwpy.timeseries import TimeSeries
from gwpy.plot import Plot
import matplotlib.pyplot as plt
plt.style.use('ggplot')
def get_tseries_from_file(file_name):
t_data = np.load(file_name)
tseries1 = TimeSeries(t_data[0,:], sample_rate=2048)
tseries2 = TimeSeries(t_data[1,:], sample_rate=2048)
tseries3 = TimeSeries(t_data[2,:], sample_rate=2048)
return tseries1, tseries2, tseries3
def plot_tseries(t1, t2, t3):
plot = Plot(t1, t2, t3, separate=True, sharex=True, figsize=[20, 12])
ax = plot.gca()
ax.set_xlim(0, 2)
ax.set_xlabel('Time [s]')
plt.show()
file_1 = root_dir + 'train/0/0/0/000a5b6e5c.npy'
tseries1, tseries2, tseries3 = get_tseries_from_file(file_1)
# Plotting the 3 TimeSeries
plot_tseries(tseries1, tseries2, tseries3)
并得到以下错误来自../gwpy/plot/plot.py
“模块‘matplotlib.pyplot’没有属性‘FigureManagerBase’”
raceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/gwpy/plot/plot.py in _init_figure(self, **kwargs)
131 try:
--> 132 manager = backend_mod.new_figure_manager_given_figure(num, self)
133 except AttributeError:
AttributeError: module 'ipykernel.pylab.backend_inline' has no attribute 'new_figure_manager_given_figure'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
3 frames
/usr/local/lib/python3.7/dist-packages/gwpy/plot/plot.py in _init_figure(self, **kwargs)
135 pyplot.new_figure_manager.__module__)
136 canvas = upstream_mod.FigureCanvasBase(self)
--> 137 manager = upstream_mod.FigureManagerBase(canvas, 1)
138 manager._cidgcf = manager.canvas.mpl_connect(
139 'button_press_event',
AttributeError: module 'matplotlib.pyplot' has no attribute 'FigureManagerBase'
附加信息
print(matplotlib.get_backend()) # module://ipykernel.pylab.backend_inline
print(matplotlib.__version__) # 3.4.3
print(gwpy.__version__) # 2.0.4
解决方案
问题的根源
在 matplotlib 3.2.2
import matplotlib.pyplot as plt
pyplot.new_figure_manager.__module__
产量:matplotlib.backend_bases
在 matplotlib 3.4.3 中,它产生:matplotlib.pyplot
这是打破:
临时解决方法
正如gwpy 的跟踪问题中所建议的那样-
目前在 Colab 中的临时解决方法是使用早期版本的 matplotlib-
!pip install matplotlib==3.2.2
有了3.2.2
它可以正常工作。
推荐阅读
- python - 无法使用机器人框架(Python)单击 div 内的链接
- ios - 几何阅读器的两种实现,但一种不工作
- python - Docker Traefik 无法路由 websocket
- azure-active-directory - OpenId Connect 身份验证和 Azure AD 范围混淆
- c++ - 为什么不将具有默认参数的函数传递给模板化构造函数并使用 lambda 将其存储为 std::function
工作? - python - 更新 4.2.1 后 Spyder 无法加载
- android - 为什么我在使用音频播放器时出错:^0.17.3 包,错误是“任务':app:processDebugManifest'的执行失败,构建失败”
- python - 带有关键字和提交事务
- google-apps-script - 为什么 Google 表格或 Google 应用程序脚本没有为我提供与显示的时间值相同的时间值?
- reactjs - 启动客户端时 React SSR 闪烁