Getting ready

To use pyplot, we will need to install matplotlib.

Because of a problem with the matplotlib installer, performing the installation using pip-3.2 doesn't always work correctly. The method that follows will overcome this problem by performing all the steps pip does manually; however, this can take over 30 minutes to complete.

 

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  
If the installation fails, it will respond with the following:

 

  ImportError: No module named matplotlib

Otherwise, there will be no errors.

Use the following steps to install matplotlib manually:

  1. 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  
  1. 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
  1. Unzip and open the matplotlib-master folder that is created, as follows:
unzip master.zip
rm master.zip
cd matplotlib-master
  1. 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  
  1. 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.16.254