Short version
Trying to show a plot via plt.show()
inside a pipenv
opens a window that is completely white, no errors. Resizing the window makes it completely black. Expecting to see a plot depicting a function f(x) = x^2
(see code below).
More info
Saving a plot with plt.savefig('tmp.png')
works fine.
Installing matplotlib
to the system wide python3 via $ pip3 install matplotlib
causes no issues. The issue only arises when matplotlib
is installed within a pipenv
executing the same code (see below).
Versions:
Somewhat surprisingly, I can get it to work on an older Mac running Sierra 10.12.6 with otherwise same versions of pipenv, python, and matplotlib. But I don't think I ever ran into the same issue on that one.
What I have tried
tcl-tk
: $ brew install tcl-tk
$ echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
What am I missing?
At this point I am out of ideas. Any hints as to how to get a plot to show up properly within a pipenv
is greatly appreciated.
Does this have anything to do with a framework install of python as mentioned in the matplotlib docs?
Code
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
if __name__ == "__main__":
plt.figure()
x = np.arange(0, 10, 1)
y = x*x
plt.plot(x, y)
# plt.savefig("tmp.png") # works fine
plt.show()
If you're still having this problem, I fixed it by installing python as a framework (I installed conda brew cask install anaconda
. Then add your Anaconda to path: export PATH=$HOME/anaconda3/bin/:$PATH
via vim ~/.bash_profile
. I can still engage pipenv with Anaconda.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With