Wednesday, 22 August 2012

Installing Matplotlib on Python3

Having recently tried to install matplotlib in a virtual environment for Python 3, I encountered some problems and decided to document the process I had to take to make sure it works:

In retrospective it actually was really easy and can be achieved with the following few steps [1]:


sudo apt-get install python3-tk tk tk-dev
pip install numpy
pip install git+https://github.com/matplotlib/matplotlib.git

This will install the necessary packages for matplotlib:

  • numpy for fast mathematical computations.
  • tk for displaying the generated plots.

After these steps the following small program should display a very simple linear graph:


import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

[1]Assuming you have already installed pip and are running Ubuntu or Linux Mint.

No comments:

Post a Comment