问题描述:代码完全没改,之前是可以显示 图片的,然后突然就不能显示了,当然可以本地存储之后再打开查看,但是也太麻烦了… 然后,网上找到的测试代码如下,理论上正常是可以显示的吗,但是我就是显示不出来…
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,50)
y = 2 * x
plt.plot(x,y)
plt.show()
在网上找到的解决方法如下,尝试过通通没用,并且有些还自相矛盾…
说法1
在开头加入下述代码:
import matplotlib
matplotlib.use(‘TkAgg’)
结果报错:
ImportError: Cannot load backend ‘TkAgg’ which requires the ‘tk’ interactive framework, as ‘headless’ is currently running
说法2:
将下述代码改成import matplotlib.pyplot as plt
:(我本来就是这个,不显示呀555,又改回去了好家伙)
import matplotlib
matplotlib.use(‘TkAgg’)
说法3:
说可能是matplotlib版本问题。
说法4:
File -> Settings -> Tools -> Python Scientific -> 去掉Show plots in tool window勾选。
说法5:
用了科学上网,将全局模式去掉。(但是还是不行555)
搜集的方法都提供如上了,有能解决的就试试吧,最后我选择保存本地再打开看… 保证能画图再说…
fig.savefig('./pic.pdf', format='pdf', dpi=550)
参考:
- pycharm使用matplotlib.pyplot不显示图形的问题:https://blog.csdn.net/baidu_39332177/article/details/119563886?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-9-119563886-blog-103092392.pc_relevant_3mothn_strategy_and_data_recovery&spm=1001.2101.3001.4242.6&utm_relevant_index=12. \
- 报错:ImportError: Cannot load backend ‘TkAgg‘ which requires the ‘tk‘ interactive:https://blog.csdn.net/qq_45571006/article/details/127156301
- plt.show仍然不能绘图:https://blog.csdn.net/weixin_43125502/article/details/103923552?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-4-103923552-blog-127156301.pc_relevant_aa2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-4-103923552-blog-127156301.pc_relevant_aa2&utm_relevant_index=5
- 【Python绘图】设置pycharm不在SciView中显示图片:https://blog.csdn.net/JianJuly/article/details/98481623
- Pycharm SciView Plots 显示不了图片:https://blog.csdn.net/qq_29598161/article/details/102643965?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-3-102643965-blog-98481623.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-3-102643965-blog-98481623.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=3