问题1:
manager_pyplot_show = vars(manager_class).get("pyplot_show")
TypeError: vars() argument must have __dict__ attribute
原因:PyCharm(至少在科学项目中)使用交互式控制台运行所有文件,使用后端module://backend_interagg。这个后端会导致和你一样的错误。
检查你使用的后端方法:
import matplotlib as mpl
print(mpl.get_backend())
解决方法:加入如下代码
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt # matplotlib.use('agg')必须在本句执行前运行