[英]Matplotlib plot window is white blank without showing any image
I am on Mac OS 10.14.4. 我在Mac OS 10.14.4上。 I have python installed in miniconda3 environment.
我在miniconda3环境中安装了python。 Below is the list of packages with "conda list"
以下是带有“ conda list”的软件包列表
The issue I am having is when I run "python" in the terminal and open the shell I try to run the codes one by one. 我遇到的问题是,当我在终端中运行“ python”并打开外壳时,我尝试一一运行这些代码。
import openmc
sp1 = openmc.StatePoint('statepoint.550-20.h5')
tally1 = sp1.tallies[1]
flux1 = tally1.mean.ravel()
import matplotlib.pyplot as plt
import numpy as np
y = np.reshape(flux1, (200,200))
plt.imshow(y, cmap=plt.cm.viridis)
plt.show()
The issue I am having is after running plt.show()
the plot window opens showing a white screen without any image in there. 我遇到的问题是运行
plt.show()
,绘图窗口打开,显示白色屏幕,其中没有任何图像。 Now if I run plt.savefig('19.7fast.png')
instead of plt.show()
i can save the image in the directory where I run the python shell in terminal. 现在,如果我运行
plt.savefig('19.7fast.png')
而不是plt.show()
我可以将图像保存在我在终端中运行python shell的目录中。
When I run import matplotlib.pyplot as plt; plt.get_backend()
当我运行
import matplotlib.pyplot as plt; plt.get_backend()
import matplotlib.pyplot as plt; plt.get_backend()
in python shell I see 'TkAgg'
, Now I tried changing to plt.switch_backend('MacOSX')
, because I looked some similar issue and similar solution. python shell中的
import matplotlib.pyplot as plt; plt.get_backend()
我看到'TkAgg'
,现在我尝试更改为plt.switch_backend('MacOSX')
,因为我看上去有一些类似的问题和类似的解决方案。 But, this gives me the error 但是,这给了我错误
ImportError: Python is not installed as a framework. ImportError:Python未作为框架安装。 The Mac OS X backend will not be able to function correctly if Python is not installed as a framework.
如果未将Python安装为框架,则Mac OS X后端将无法正常运行。 See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
有关在Mac OS X上将Python安装为框架的更多信息,请参见Python文档。请重新安装Python作为框架,或尝试其他后端之一。 If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'.
如果您正在使用(Ana)Conda,请安装python.app并将“ python”的使用替换为“ pythonw”。 See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
有关更多信息,请参见Matplotlib FAQ中的“在OSX上使用Matplotlib”。
Any help to resolve this issue is much appriciated 解决此问题的任何帮助都非常有用
In my experience, to get this working on Mac OS, I found it much easier going with the full version of Anaconda and using VS Code as an Editor/IDE. 以我的经验,要使其在Mac OS上运行,我发现使用完整版本的Anaconda并使用VS Code作为Editor / IDE容易得多。
Uninstall Miniconda: 卸载Miniconda:
rm -rf ~/miniconda.
rm -rf ~/.condarc ~/.conda ~/.continuum
Install Anaconda and VS Code: 安装Anaconda和VS Code:
Go to the installation website and download the Mac OS installer (I recommend choosing the latest version of Python (3.7) 转到安装网站并下载Mac OS安装程序(我建议选择最新版本的Python(3.7)
Follow the installation instructions 请遵循安装说明
VS Code Install/Launch VS代码安装/启动
Run a test script 运行测试脚本
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-4*np.pi,4*np.pi)
y = np.sin(x)
plt.plot(x,y,'.-')
plt.show()
Ctrl+Shift+P
) Ctrl+Shift+P
) Ctrl+Shift+P
) Ctrl+Shift+P
) python test.py
Hopefully, this will all work and you'll see the following: 希望这一切都会起作用,您将看到以下内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.