To use pyplot, we will need to install matplotlib.
To save time, you can try the pip installation, which is much quicker. If it doesn't work, you can install it using the aforementioned manual method.
Use the following commands to try to install matplotlib using pip:
sudo apt-get install tk-dev python3-tk libpng-dev
sudo pip-3.2 install numpy
sudo pip-3.2 install matplotlib
You can confirm that matplotlib has been installed by running python3 and trying to import it from the Python Terminal, as follows:
import matplotlib
ImportError: No module named matplotlib
Otherwise, there will be no errors.
Use the following steps to install matplotlib manually:
- Install the support packages as follows:
sudo apt-get install tk-dev python3-tk python3-dev libpng-dev sudo pip-3.2 install numpy sudo pip-3.2 install matplotlib
- Download the source files from the Git repository (the command should be a single line) as follows:
wget https://github.com/matplotlib/matplotlib/archive/master.zip
- Unzip and open the matplotlib-master folder that is created, as follows:
unzip master.zip rm master.zip cd matplotlib-master
- Run the setup file to build (this will take a while) and install it as follows:
sudo python3 setup.py build sudo python3 setup.py install
- Test the installation in the same way as the automated install.
We will either need the PCF8591 ADC module (and wiringpi2, installed as before), or we can use the data_local.py module from the previous section (just replace data_adc with data_local in the import section of the script). We also need to have data_adc.py and data_local.py in the same directory as the new script, depending on which you use.