The reason is because I’m a heavy user of Python virtual environments and strictly believe in keeping my Python environments sequestered and independent of each other. The astute Debian user may be wondering why I didn’t simply install matplotlib via apt - get , like this:
Ubuntu install matplotlib install#
Can’t you just install matplotlib via apt-get? If you are having the same problems with matplotlib figures not displaying on your Raspberry Pi, the fix detailed in this blog post will resolve your plotting woes. The Raspbian operating system, which many Raspberry Pi’s run, is Debian based just like Ubuntu. If you have any other suggestions or comments, please feel free to leave them in the comments section. Granted, this solution is a bit of a pain in the ass, but it’s fairly straightforward and gets the job done. We have now fixed our issue - matplotlib figures are successfully being displayed on our screen!
Ubuntu install matplotlib code#
When I execute the code on my OSX machine in the plotting virtual environment, the histogram is computed and both the grayscale image and histogram are displayed to my screen:įigure 4: Success! Our matplotlib figure is now showing up! All we need to do was change the matplotlib backend. To execute our script, all we need to do is fire up and shell and issue the following command: Finally, Lines 14-22 plot the histogram using matplotlib . calcHist function is used to compute a histogram over the grayscale pixel intensities. We then load our image and convert it to grayscale ( Lines 4-9). Lines 1 and 2 import matplotlib and cv2 . # load the image, convert it to grayscale, and show it And our goal is to take the following image (left) and compute a grayscale pixel intensity histogram for it using matplotlib (right):.We’re (optionally) utilizing Python virtual environments via virtualenv and virtualenvwrapper.We’re using a Debian based operating system such as Ubuntu or Raspbian.Matplotlib is a heavily used package in the Python scientific community and I hope that this article helps other readers resolve this strange and hard to pinpoint issue. While this post is not exactly related to computer vision or OpenCV, I still want to share my experience and solution with other PyImageSearch readers.
Ubuntu install matplotlib trial#
Luckily, after a lot of trial and error (and spending an entire day trying to come up with a solution), I have been able to resolve the problem and get matplotlib figures to show up and display on my screen on both the Ubuntu and Raspbian operating systems (and when using Python virtual environments). The issue actually stems from the matplotlib backend not being properly set, or from a missing dependency when compiling and installing matplotlib. This issue is only further compounded when utilizing virtual environments via the virtualenv and virtualenvwrapper packages. This is actually a common problem I’ve ran into over the past few months, especially when working with Debian based operating systems such as Ubuntu and Raspbian. I coded up a quick Python script using matplotlib, executed the script, only to not have the figure displayed to my screen. Over the weekend I was playing around with deep learning on my Ubuntu system and went to plot the accuracy scores of my classifier. I think a better title for this blog post might be: How I lost a day of productivity to Ubuntu, virtual environments, matplotlib, and rendering backends.