Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Data Visualization Cookbook (Second Edition)

You're reading from   Python Data Visualization Cookbook (Second Edition) Visualize data using Python's most popular libraries

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781784396695
Length 302 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. Preparing Your Working Environment FREE CHAPTER 2. Knowing Your Data 3. Drawing Your First Plots and Customizing Them 4. More Plots and Customizations 5. Making 3D Visualizations 6. Plotting Charts with Images and Maps 7. Using the Right Plots to Understand Data 8. More on matplotlib Gems 9. Visualizations on the Clouds with Plot.ly Index

Installing matplotlib on Mac OS X

The easiest way to get matplotlib on the Mac OS X is to use prepackaged python distributions such as Enthought Python Distribution (EPD). Just go to the EPD site, and download and install the latest stable version for your OS.

In case you are not satisfied with EPD or cannot use it for other reasons such as the versions distributed with it, there is a manual (read: harder) way of installing Python, matplotlib, and its dependencies.

Getting ready

We will use the Homebrew (you could also use MacPorts in the same way) project that eases the installation of all software that Apple did not install on your OS, including Python and matplotlib. Under the hood, Homebrew is a set of Ruby and Git that automate download and installation. Following these instructions should get the installation working. First, we will install Homebrew, and then Python, followed by tools such as virtualenv, then dependencies for matplotlib (NumPy and SciPy), and finally matplotlib. Hold on, here we go.

How to do it...

  1. In your terminal, paste and execute the following command:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    After the command finishes, try running brew update or brew doctor to verify that the installation is working properly.

  2. Next, add the Homebrew directory to your system path, so the packages you install using Homebrew have greater priority than other versions. Open ~/.bash_profile (or /Users/[your-user-name]/.bash_profile) and add the following line to the end of file:
    export PATH=/usr/local/bin:$PATH
    
  3. You will need to restart the terminal so that it picks a new path. Installing Python is as easy as firing up another one liner:
    brew install python --framework --universal

    This will also install any prerequisites required by Python.

  4. Now, you need to update your path (add to the same line):
    export PATH=/usr/local/share/python:/usr/local/bin:$PATH
  5. To verify that the installation has worked, type python --version in the command line, you should see 2.7.3 as the version number in the response.
  6. You should have pip installed by now. In case it is not installed, use easy_install to add pip:
    $ easy_install pip
    
  7. Now, it's easy to install any required package; for example, virtualenv and virtualenvwrapper are useful:
    pip install virtualenv
    pip install virtualenvwrapper
    
  8. The next step is what we really wanted to do all along—install matplotlib:
    pip install numpy
    brew install gfortran
    pip install scipy
    
  9. Verify that everything is working. Call Python and execute the following commands:
    import numpy
    print numpy.__version__
    import scipy
    print scipy.__version__
    quit()
    
  10. Install matplotlib:
    pip install matplotlib
    
You have been reading a chapter from
Python Data Visualization Cookbook (Second Edition)
Published in: Nov 2015
Publisher:
ISBN-13: 9781784396695
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime