Python Data Visualization Cookbook 2nd Edition Igor Milovanovicinstant download
Python Data Visualization Cookbook 2nd Edition Igor Milovanovicinstant download
or textbooks at https://ebookultra.com
https://ebookultra.com/download/python-data-visualization-
cookbook-2nd-edition-igor-milovanovic/
https://ebookultra.com/download/python-cookbook-third-edition-beazley/
https://ebookultra.com/download/python-cookbook-1st-edition-alex-
martelli/
https://ebookultra.com/download/python-cookbook-3rd-edition-david-
beazley/
Python cookbook 3ed. Edition Beazley D.
https://ebookultra.com/download/python-cookbook-3ed-edition-beazley-d/
https://ebookultra.com/download/ipython-interactive-computing-and-
visualization-cookbook-1st-edition-cyrille-rossant/
https://ebookultra.com/download/data-visualization-with-d3-and-
angularjs-1st-edition-korner/
https://ebookultra.com/download/maya-programming-with-python-
cookbook-1st-edition-herbez/
Data Driven SEO with Python Solve SEO Challenges with Data
Science Using Python 4th Edition Andreas Voniatis
https://ebookultra.com/download/data-driven-seo-with-python-solve-seo-
challenges-with-data-science-using-python-4th-edition-andreas-
voniatis/
Python Data Visualization Cookbook 2nd Edition Igor
Milovanovic Digital Instant Download
Author(s): Igor Milovanovic, Dimitry Foures, Giuseppe Vettigli
ISBN(s): 9781784396695, 1784396699
Edition: 2nd
File Details: PDF, 19.66 MB
Year: 2015
Language: english
www.it-ebooks.info
Python Data Visualization
Cookbook
Second Edition
Igor Milovanović
Dimitry Foures
Giuseppe Vettigli
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Python Data Visualization Cookbook
Second Edition
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the authors, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be
caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78439-669-5
www.packtpub.com
www.it-ebooks.info
Credits
Reviewer
Kostiantyn Kucher Indexer
Rekha Nair
Commissioning Editor
Akram Hussain Graphics
Jason Monteiro
Acquisition Editor
Meeta Rajani Production Coordinator
Manu Joseph
Technical Editor
Anushree Arun Tendulkar
Copy Editor
Charlotte Carneiro
www.it-ebooks.info
About the Authors
Evangelist for high-quality systems design who holds strong interests in software architecture
and development methodologies, Igor is always persistent on advocating methodologies
which promote high-quality software, such as test-driven development, one-step builds and
continuous integration.
He also possesses solid knowledge of product development. Having field experience and
official training, he is capable of transferring knowledge and communication flow from
business to developers and vice versa.
Igor is most grateful to his girlfriend for letting him spent hours on the work instead with
her and being avid listener to his endless book monologues. He thanks his brother for
being the strongest supporter. He is thankful to his parents to let him develop in various
ways and become a person he is today.
Giuseppe Vettigli is a data scientist who has worked in the research industry and
academia for many years. His work is focused on the development of machine learning
models and applications to use information from structured and unstructured data.
He also writes about scientific computing and data visualization in Python on his blog
at http://glowingpython.blogspot.com.
www.it-ebooks.info
About the Reviewer
Kostiantyn Kucher was born in Odessa, Ukraine. He received his master's degree in
computer science from Odessa National Polytechnic University in 2012, and he has used
Python as well as matplotlib and PIL for machine learning and image recognition purposes.
Since 2013, Kostiantyn has been a PhD student in computer science specializing in information
visualization. He conducts his research under the supervision of Prof. Dr. Andreas Kerren with
the ISOVIS group at the Computer Science department of Linnaeus University (Växjö, Sweden).
Kostiantyn was a technical reviewer for the first edition of this book.
www.it-ebooks.info
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can search, access, and read Packt's entire library of books.
Why Subscribe?
ff Fully searchable across every book published by Packt
ff Copy and paste, print, and bookmark content
ff On demand and accessible via a web browser
www.it-ebooks.info
Table of Contents
Preface v
Chapter 1: Preparing Your Working Environment 1
Introduction 1
Installing matplotlib, NumPy, and SciPy 2
Installing virtualenv and virtualenvwrapper 4
Installing matplotlib on Mac OS X 7
Installing matplotlib on Windows 9
Installing Python Imaging Library (PIL) for image processing 10
Installing a requests module 11
Customizing matplotlib's parameters in code 12
Customizing matplotlib's parameters per project 14
Chapter 2: Knowing Your Data 17
Introduction 17
Importing data from CSV 18
Importing data from Microsoft Excel files 20
Importing data from fixed-width data files 23
Importing data from tab-delimited files 25
Importing data from a JSON resource 27
Exporting data to JSON, CSV, and Excel 29
Importing and manipulating data with Pandas 34
Importing data from a database 35
Cleaning up data from outliers 40
Reading files in chunks 45
Reading streaming data sources 47
Importing image data into NumPy arrays 49
Generating controlled random datasets 55
Smoothing the noise in real-world data 62
www.it-ebooks.info
Table of Contents
ii
www.it-ebooks.info
Table of Contents
Plotting data on a map using the Google Map API 179
Generating CAPTCHA images 185
Chapter 7: Using the Right Plots to Understand Data 191
Introduction 191
Understanding logarithmic plots 192
Understanding spectrograms 195
Creating stem plot 200
Drawing streamlines of vector flow 204
Using colormaps 208
Using scatter plots and histograms 213
Plotting the cross correlation between two variables 221
Importance of autocorrelation 224
Chapter 8: More on matplotlib Gems 229
Introduction 229
Drawing barbs 229
Making a box-and-whisker plot 233
Making Gantt charts 236
Making error bars 241
Making use of text and font properties 244
Rendering text with LaTeX 251
Understanding the difference between pyplot and OO API 255
Chapter 9: Visualizations on the Clouds with Plot.ly 261
Introduction 261
Creating line charts 262
Creating bar charts 266
Plotting a 3D trefoil knot 269
Visualizing maps and bubbles 272
Index 275
iii
www.it-ebooks.info
www.it-ebooks.info
Preface
The best data is the data that we can see and understand. As developers and data scientists,
we want to create and build the most comprehensive and understandable visualizations.
It is not always simple; we need to find the data, read it, clean it, filter it, and then use the
right tool to visualize it. This book explains the process of how to read, clean, and visualize
the data into information with straight and simple (and sometimes not so simple) recipes.
How to read local data, remote data, CSV, JSON, and data from relational databases are all
explained in this book.
Some simple plots can be plotted with one simple line in Python using matplotlib, but
performing more advanced charting requires knowledge of more than just Python. We need
to understand information theory and human perception aesthetics to produce the most
appealing visualizations.
This book will explain some practices behind plotting with matplotlib in Python, statistics used,
and usage examples for different charting features that we should use in an optimal way.
Chapter 2, Knowing Your Data, introduces you to common data formats and how to read and
write them, be it CSV, JSON, XSL, or relational databases.
Chapter 3, Drawing Your First Plots and Customizing Them, starts with drawing simple plots
and covers some customization.
Chapter 4, More Plots and Customizations, follows up from the previous chapter and covers
more advanced charts and grid customization.
www.it-ebooks.info
Preface
Chapter 6, Plotting Charts with Images and Maps, deals with image processing, projecting
data onto maps, and creating CAPTCHA test images.
Chapter 7, Using Right Plots to Understand Data, covers explanations and recipes on some
more advanced plotting techniques such as spectrograms and correlations.
Chapter 8, More on matplotlib Gems, covers a set of charts such as Gantt charts, box plots,
and whisker plots, and it also explains how to use LaTeX for rendering text in matplotlib.
Chapter 9, Visualizations on the Clouds with Plot.ly, introduces how to use Plot.ly to create
and share your visualizations on its cloud environment.
Another software package used in this book is IPython, which is an interactive Python
environment that is very powerful and flexible. This can be installed using package
managers for Linux-based OSes or prepared installers for Windows and Mac OS X.
If you are new to Python installation and software installation in general, it is highly
recommended to use prepackaged scientific Python distributions such as Anaconda,
Enthought Python Distribution or Python(x, y).
Other required software mainly comprises Python packages that are all installed using the
Python installation manager, pip, which itself is installed using Python's easy_install setup tool.
You will need to know some general programming concepts, and any kind of programming
experience will be helpful. However, the code in this book is explained almost line by line.
You don't need math for this book; every concept that is introduced is thoroughly explained
in plain English, and references are available for further interest in the topic.
vi
www.it-ebooks.info
Preface
Sections
In this book, you will find several headings that appear frequently (Getting ready, How to do it,
How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
Getting ready
This section tells you what to expect in the recipe, and describes how to set up any software or
any preliminary settings required for the recipe.
How to do it…
This section contains the steps required to follow the recipe.
How it works…
This section usually consists of a detailed explanation of what happened in the previous section.
There's more…
This section consists of additional information about the recipe in order to make the reader
more knowledgeable about the recipe.
See also
This section provides helpful links to other useful information for the recipe.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames,
dummy URLs, user input, and Twitter handles are shown as follows: "We packed our little demo
in the DemoPIL class, so that we can extend it easily, while sharing the common code around
the demo function, run_fixed_filters_demo."
vii
www.it-ebooks.info
Preface
When we wish to draw your attention to a particular part of a code block, the relevant lines or
items are set in bold:
for a in range(10):
print a
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.
viii
www.it-ebooks.info
Exploring the Variety of Random
Documents with Different Content
EPIDENDRUM VITELLINUM MAJUS. PL. 4.
8
EPIDENDRUM VITELLINUM MAJUS.
[Plate 4.]
Native of Mexico.
The variety majus blooms at a different time of the year from the
original species, which has the flowers much smaller, and which
blooms in August and September from the young growths; whereas
the variety majus flowers from the tips of the bulbs of the previous
year’s growth. There are several forms of the plant, some with
flowers much larger and brighter than others; indeed, the one here
figured is not so large as some that were flowered years ago, which
may be due to the fact that they were old-established plants. We
remember the late Mrs. Lawrence, of Ealing Park, exhibiting a
remarkably strong specimen at one of the Chiswick shows, thirty-five
years since, a perfect blaze of flower. S. Brunton, Esq., also exhibited
a grand plant of a good variety a few years back; and C. W. Lea,
Esq., Parkfield, Worcester, had a wonderful example in bloom, last
year. These several plants were all part of the early importations.
The Manchester Show of Orchids, June, 1881.—The display of Orchids at
the Manchester Exhibition was a very fine one, and no Orchid grower
should have missed the sight. The specimens were truly marvellous,
especially the sixteen plants shown by R. Dodgson, Esq., of
Blackburn, amongst which were a Vanda suavis with about a dozen
flower-spikes; Lælia purpurata and Cattleya Warneri, both wonderful
specimens, as also was Masdevallia Harryana; Cypripedium barbatum
superbum which had a hundred blooms upon it, and was not made
up for the occasion, but had been grown on from a single plant; and
Dendrobium Wardianum which was a magnificent plant. Great credit
is due to Mr. Osman for his talent, in successfully cultivating so fine a
collection. G. Hardy, Esq., of Timperley, exhibited some wonderful
plants, especially of Cattleyas, Lælias, Dendrobium thyrsiflorum,
Oncidium Marshallianum, Odontoglossum vexillarium, &c. R. F.
Ainsworth, Esq., M.D., also exhibited some fine specimens, especially
Vanda suavis, Aërides Fieldingii, and A. Schröderii; these three are
most extraordinary plants, and have been grown in the collection for
eighteen years, which is a sufficient proof of what can be done by
perseverance, and, moreover, gives one an idea how well Orchids can
be grown and exhibited for many successive years. We have known
these three specimens to be shown at the Manchester exhibitions and
elsewhere for the past ten or fifteen years, and they are now in the
finest possible condition, as they have always been, under the
successful management of Mr. Mitchell. There were besides, other
exhibitors whose specimens were well worthy of note.—B. S. W.
MASDEVALLIA SHUTTLEWORTHII. PL. 5.
10
MASDEVALLIA SHUTTLEWORTHII.
[Plate 5.]
Native of the United States of Colombia.
14
PROMENÆA CITRINA.
[Plate 7.]
Native of Brazil.
Fibrous peat and sphagnum moss seem to suit the plant well when it
is grown in either pots or pans; but when cultivated on blocks of
wood, a little sphagnum moss only about its roots will be quite
sufficient, though if grown in this latter way it requires a more liberal
and more frequent supply of water, in order to keep the roots moist.
We find the Cattleya-house to suit it best, and we grow it suspended
against a wall at the end of the house, where it gets syringed in
warm weather. The manner in which its blooms are produced may be
seen from our Illustration, which is an excellent representation of the
habit of the plant, not only as regards its general manner of growth,
but also of its mode of flowering.
CYPRIPEDIUM STONEI. PL. 8.
16
CYPRIPEDIUM STONEI.
[Plate 8.]
Native of Borneo.
18
LÆLIA PURPURATA WILLIAMSII.
[Plates 9-10.]
Native of St. Catherine’s, Brazil.
The species, of which this is one of the finest known varieties, and
the genus Lælia to which it belongs, together with the neighbouring
genus Cattleya, are placed by the great Orchidist, Reichenbach, in his
amplified genus Bletia, so that the Lælia purpurata of Lindley, in
Paxton’s Flower Garden, becomes the Bletia purpurata of
Reichenbach in Walpers’ Annales, vi. 423. The name of Lælia is,
however, that which is adopted amongst cultivators of Orchids.
The Lælia which we have now to describe, was named many years
ago in the Orchid Grower’s Manual, when it was exhibited at the
Crystal Palace and received its present appellation. The plant now
represented was flowered at the Victoria and Paradise Nurseries, but
has now passed into the select collection of Baron Schröder, of The
Dell, near Staines. It was a wonderfully strong plant, and produced
two spikes of its highly coloured blossoms, which led all those who
saw it in its beauty, to pronounce it to be the finest Lælia they had
ever witnessed. Our artist has given a good representation of the
plant and its blossoms. The club-shaped stems and foliage stood
thirty inches in height, and were provided with very strong sheathing
bracts whence the flower-spikes issued, each bearing four flowers,
which were individually eight inches in diameter. It has bloomed with
us in the same style for two successive years. The plant that we
flowered some years ago was not so large as that now figured, the
reason being that it was not so strong a specimen, and, therefore,
not able to produce such fine flowers. This is sufficient 19
evidence of the advance the plants make before they get to
their full strength and vigour. In the variety before us the sepals and
petals are of a delicate rose, veined with a beautiful dark tint of the
same colour, while the lip is very broad, large, and splendidly
coloured, the prominent parts of a rich dark crimson-magenta, paler
and veiny at the tip, and beautifully veined with crimson on the
yellow ground-colour of the throat. The blooming season is in May
and June, the flowers continuing in perfection for three or four
weeks, if kept free from damp and in a dry place. We have a house
set aside specially for Orchids when in flower, and in it very little
moisture is used, by which means we seldom get the flowers spotted
or prematurely decayed.
There is another fine form of Lælia purpurata with white sepals and
petals that are quite flat, not at all recurved; this variety has a rich
dark crimson-magenta lip. We exhibited this form with nine flower
spikes at the Regent’s Park Exhibition, and it produced a grand effect.
There are many other fine varieties.
Lælia purpurata when well cultivated is a good looking plant, and
even when not in bloom it is an object of attraction, on account of its
stately evergreen foliage. It is a native of Brazil, and is found growing
on the branches of trees on the outskirts of the forests where the
plants get light, and are yet shaded from the burning sun. They are
best grown in the Cattleya-house, and will thrive either in pots or
baskets, but we find the pot system the best, as they are strong
growing plants, and require ample space to bring them to perfection.
They are the better for being moved about, especially if they are
required for exhibition. There are no more showy Orchids for
exhibition purposes, and this is especially true of such varieties as
that now before us.
We find that they thrive best in good fibrous peat, and some live
sphagnum moss on a part of the surface; when in a growing state
the moss keeps them moist without too much water being given
whilst they are making their growth. In watering them be careful not
to wet the young shoots. The pots should be three parts filled with
drainage, which must be formed of broken pots and lumps of
charcoal intermixed. The plants must be elevated about two inches
above the rim of the pot. The best time to pot them is after they
have done blooming just as they begin to make new growths, and
before the roots start, when they will soon commence to work into
the clean sweet peat. If the plant is in a sufficiently large pot, and the
soil about it is sweet and clean, it will not require re-potting, but it
will benefit the plants greatly to give them some fresh fibrous peat
just before they begin to root, as the old soil is apt to become hard
and inert through constant watering. They require to be kept moist
during the growing season, but must not even then be soddened with
water. In winter only just sufficient must be given them to keep them
moist, and to prevent their stems and leaves from shriveling.
PHALÆNOPSIS AMABILIS DAYANA. PL. 11.
20
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com