Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Python Data Visualization

You're reading from  Mastering Python Data Visualization

Product type Book
Published in Oct 2015
Publisher
ISBN-13 9781783988327
Pages 372 pages
Edition 1st Edition
Languages

Table of Contents (16) Chapters

Mastering Python Data Visualization
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
A Conceptual Framework for Data Visualization Data Analysis and Visualization Getting Started with the Python IDE Numerical Computing and Interactive Plotting Financial and Statistical Models Statistical and Machine Learning Bioinformatics, Genetics, and Network Models Advanced Visualization Go Forth and Explore Visualization Index

Appendix A. Go Forth and Explore Visualization

Python has been around since 1991 and has gained popularity among the community of scientists and engineers. Among many libraries, numpy, scipy, and matplotlib have been widely used in scientific computing. Sage covers the areas of algebra, combinatorics, numerical mathematics, number theory, and calculus using an easy browser interface via IPython. Another popular package called pandas can be used to store and process complex datasets.

There are multiple tools to run and edit Python programs, and one among them is Anaconda from Continuum. One of the advantages of Anaconda is that it does not cost anything and comes inbuilt with most necessary packages. The underlying command-line tool for managing environments and Python packages is conda, and the editor is Spyder.

In the past, installing Spyder was complicated because it involved downloading and installing it in a multistep process. Installation in the recent versions has been very straightforward, and one can download and install all the components together automatically in one step.

An overview of conda


Conda is a command line-tool that is responsible for managing environments and Python packages, rather than using pip. There are ways to query and search the packages, create new environments if necessary, and install and update Python packages into the existing conda environments. This command-line tool also keeps track of dependencies between packages and platform specifics, helping you to create working environments from different combinations of packages. To check the version of conda that is running, you can enter conda --version in Python and it will show, for example, conda 3.18.2 as the version.

A conda environment is a filesystem directory that contains a specific collection of conda packages. To begin using an environment, simply set the PATH variable to point it to its bin directory.

Here is an example of the package installation from the command line using conda:

$ conda install scipy

Fetching package metadata: ....
Solving package specifications: .
Package plan for installation in environment /Users/MacBook/anaconda:

The following packages will be downloaded:

    package                |       build
    ---------------------|-----------------
    flask-0.10.1         |       py27_1         129 KB
    itsdangerous-0.23    |       py27_0          16 KB
    jinja2-2.7.1         |       py27_0         307 KB
    markupsafe-0.18      |       py27_0          19 KB
    werkzeug-0.9.3       |       py27_0         385 KB

The following packages will be linked:

    package              |            build
    ---------------------|-----------------
    flask-0.10.1         |       py27_1
    itsdangerous-0.23    |       py27_0
    jinja2-2.7.1         |       py27_0
    markupsafe-0.18      |       py27_0
    python-2.7.5         |       2
    readline-6.2         |       1
    sqlite-3.7.13        |       1
    tk-8.5.13            |       1
    werkzeug-0.9.3       |       py27_0
    zlib-1.2.7           |       1

Proceed ([y]/n)? 

Any dependencies on the package that we are installing will be recognized, downloaded, and linked automatically.

Here is an example of package update from the command line using conda:

$ conda update matplotlib
Fetching package metadata: ....
Solving package specifications: .
Package plan for installation in environment /Users/MacBook/anaconda:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    freetype-2.5.2             |                0         691 KB
    conda-env-2.1.4            |           py27_0          15 KB
    numpy-1.9.2                |           py27_0         2.9 MB
    pyparsing-2.0.3            |           py27_0          63 KB
    pytz-2015.2                |           py27_0         175 KB
    setuptools-15.0            |           py27_0         436 KB
    conda-3.10.1               |           py27_0         164 KB
    python-dateutil-2.4.2      |           py27_0         219 KB
    matplotlib-1.4.3           |       np19py27_1        40.9 MB
    ------------------------------------------------------------
                                           Total:        45.5 MB

The following NEW packages will be INSTALLED:

    python-dateutil: 2.4.2-py27_0    

The following packages will be UPDATED:

    conda:             3.10.0-py27_0    --> 3.10.1-py27_0   
    conda-env:       2.1.3-py27_0     --> 2.1.4-py27_0    
    freetype:   2.4.10-1         --> 2.5.2-0         
    matplotlib:     1.4.2-np19py27_0 --> 1.4.3-np19py27_1
    numpy:          1.9.1-py27_0     --> 1.9.2-py27_0    
    pyparsing:      2.0.1-py27_0     --> 2.0.3-py27_0    
    pytz:           2014.9-py27_0    --> 2015.2-py27_0   
    setuptools:     14.3-py27_0      --> 15.0-py27_0     

Proceed ([y]/n)?

In some cases, there are more steps involved in installing a package via conda. For instance, to install wordcloud, you will have to perform the steps given in this code:

#step-1 command
conda install wordcloud

Fetching package metadata: ....
Error: No packages found in current osx-64 channels matching: wordcloud

You can search for this package on Binstar with
# This only means one has to search the source location
binstar search -t conda wordcloud

Run 'binstar show <USER/PACKAGE>' to get more details:
Packages:
                          Name | Access       | Package Types   | 
     ------------------------- | ------------ | --------------- |
             derickl/wordcloud | public       | conda           |
Found 1 packages

# step-2 command
binstar show derickl/wordcloud

Using binstar api site https://api.binstar.org
Name:    wordcloud
Summary:
Access:  public
Package Types:  conda
Versions:
   + 1.0

To install this package with conda run:
conda install --channel https://conda.binstar.org/derickl wordcloud

# step-3 command
conda install --channel https://conda.binstar.org/derickl wordcloud

Fetching package metadata: ......
Solving package specifications: .
Package plan for installation in environment /Users/MacBook/anaconda:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cython-0.22                |           py27_0         2.2 MB
    django-1.8                 |           py27_0         3.2 MB
    pillow-2.8.1               |           py27_1         454 KB
    image-1.3.4                |           py27_0          24 KB
    setuptools-15.1            |           py27_1         435 KB
    wordcloud-1.0              |       np19py27_1          58 KB
    conda-3.11.0               |           py27_0         167 KB
    ------------------------------------------------------------
                                           Total:         6.5 MB

The following NEW packages will be INSTALLED:
    django:     1.8-py27_0
    image:      1.3.4-py27_0
    pillow:     2.8.1-py27_1
    wordcloud:  1.0-np19py27_1

The following packages will be UPDATED:
    conda:      3.10.1-py27_0 --> 3.11.0-py27_0
    cython:     0.21-py27_0   --> 0.22-py27_0
    setuptools: 15.0-py27_0   --> 15.1-py27_1



Finally, the following packages will be downgraded:

    libtiff:    4.0.3-0       --> 4.0.2-1

Proceed ([y]/n)? y

Anaconda is a free Python distribution for scientific computing. This distribution comes with Python 2.x or Python 3.x and 100+ cross-platform tested and optimized Python packages. Anaconda can also create custom environments that mix and match different Python versions.

Packages installed with Anaconda


The following command will display a list of all the packages in the Anaconda environment:

conda list 

The featured packages in Anaconda are Astropy, Cython, h5py, IPython, LLVM, LLVMpy, matplotlib, Mayavi, NetworkX, NLTK, Numexpr, Numba, numpy, pandas, Pytables, scikit-image, scikit-learn, scipy, Spyder, Qt/PySide, and VTK.

In order to check the packages that are installed with Anaconda, navigate to the command line and enter the conda list command to quickly display a list of all the packages installed in the default environment. Alternatively, you can also check Continuum Analytics for details on the list of packages available in the current and latest release.

In addition, you can always install a package with the usual means, for example, using the pip install command or from the source using a setup.py file. Although conda is the preferred packaging tool, there is nothing special about Anaconda that prevents the usage of standard Python packaging tools.

Note

IPython is not required, but it is highly recommended. IPython should be installed after Python, GNU Readline, and PyReadline are installed. Anaconda and Canopy does these things by default. There are Python packages that are used in all the examples in this book for a good reason. In the following section, we have updated the list.

Packages websites


Here is a list of Python packages that we have mentioned in this book with their respective websites, where you can find the most up-to-date information:

About matplotlib


The matplotlib package comes with many convenient methods to create visualization charts and graphs. Only a handful of these have been explored in this book. You will have to explore matplotlib further from the following sources:

One should also refer to other packages listed in the previous section, which are libraries that make plotting more attractive.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Python Data Visualization
Published in: Oct 2015 Publisher: ISBN-13: 9781783988327
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 $15.99/month. Cancel anytime}