Matplotlib Plot Window Is White Blank Without Showing Any Image
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 te
Solution 1:
I was able to fix the issue with macOS Majave 10.14.6
without having to reinstall via Anaconda/Conda by adding this code (as explained in https://stackoverflow.com/a/56025793/1657354):
import matplotlib
import platform
if platform.system() == 'Darwin':
matplotlib.use('MacOSX')
else:
matplotlib.use('TkAgg')
I believe the platform.system() == 'Darwin'
allows this code to work under other platforms.
Solution 2:
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:
- Open a terminal window and remove the entire miniconda install directory:
rm -rf ~/miniconda.
- You can also edit ```~/.bash_profile`` and remove the miniconda directory from your PATH environment variable
- Remove the hidden .condarc file and .conda and .continuum directories which are usually created in your directory:
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
- Once installed open the Anaconda Navigator and select the option to install VS code:
Run a test script
- Open VS Code via the Anaconda Installer
- Create a new script: File > New File
- Save it as "test.py"
- Enter the following code:
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()
- Save the file
- Select the Anaconda Python interpreter:
- Open the command pallet (
Ctrl+Shift+P
) - Enter "Python: Select Interpreter"
- Choose the one that says "anaconda" in the name...
- Open the command dialog box again (
Ctrl+Shift+P
) - Enter "Python: Create Terminal" and in terminal run:
python test.py
Hopefully, this will all work and you'll see the following:
Post a Comment for "Matplotlib Plot Window Is White Blank Without Showing Any Image"