I am on Mac OS 10.14.4. I have python installed in miniconda3 environment. Below is the list of packages with "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.
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. 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.
When I run 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. But, this gives me the error
ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. 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. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
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.
Uninstall Miniconda:
rm -rf ~/miniconda.
rm -rf ~/.condarc ~/.conda ~/.continuum
Install Anaconda and VS Code:
Go to the installation website and download the Mac OS installer (I recommend choosing the latest version of Python (3.7)
Follow the installation instructions
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
) python test.py
Hopefully, this will all work and you'll see the following:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.