Python Data Visualization Cookbook - Second Edition
Format: PDF / Kindle (mobi) / ePub
Over 70 recipes to get you started with popular Python libraries based on the principal concepts of data visualization
About This Book
- Learn how to set up an optimal Python environment for data visualization
- Understand how to import, clean and organize your data
- Determine different approaches to data visualization and how to choose the most appropriate for your needs
Who This Book Is For
If you already know about Python programming and want to understand data, data formats, data visualization, and how to use Python to visualize data then this book is for you.
What You Will Learn
- Introduce yourself to the essential tooling to set up your working environment
- Explore your data using the capabilities of standard Python Data Library and Panda Library
- Draw your first chart and customize it
- Use the most popular data visualization Python libraries
- Make 3D visualizations mainly using mplot3d
- Create charts with images and maps
- Understand the most appropriate charts to describe your data
- Know the matplotlib hidden gems
- Use plot.ly to share your visualization online
Python Data Visualization Cookbook will progress the reader from the point of installing and setting up a Python environment for data manipulation and visualization all the way to 3D animations using Python libraries. Readers will benefit from over 60 precise and reproducible recipes that will guide the reader towards a better understanding of data concepts and the building blocks for subsequent and sometimes more advanced concepts.
Python Data Visualization Cookbook starts by showing how to set up matplotlib and the related libraries that are required for most parts of the book, before moving on to discuss some of the lesser-used diagrams and charts such as Gantt Charts or Sankey diagrams. Initially it uses simple plots and charts to more advanced ones, to make it easy to understand for readers. As the readers will go through the book, they will get to know about the 3D diagrams and animations. Maps are irreplaceable for displaying geo-spatial data, so this book will also show how to build them. In the last chapter, it includes explanation on how to incorporate matplotlib into different environments, such as a writing system, LaTeX, or how to create Gantt charts using Python.
Style and approach
A step-by-step recipe based approach to data visualization. The topics are explained sequentially as cookbook recipes consisting of a code snippet and the resulting visualization.
value (price_today). If we wanted more control, we could use different distributions. The following code illustrates and visualizes different distributions. We will comment separate code sections as we present them. We start by importing required modules and defining a number of histogram buckets. We also create a figure that will hold our histograms. # coding: utf-8 import random import matplotlib import matplotlib.pyplot as plt SAMPLE_SIZE = 1000 59 Knowing Your Data # histogram buckets
the code is developed on Ubuntu 12.03 using Python 2.7, IPython 0.13.2, virtualenv 1.9.1, matplotlib 1.2.1, NumPy 1.7.1, and SciPy 0.11.0. What this book covers Chapter 1, Preparing Your Working Environment, covers a set of installation recipes and advices on how to install the required Python packages and libraries on your platform. 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,
you understand data, data formats, data visualization, and how to use Python to visualize data. 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. Conventions In this book, you will find a number of
draw_path method. Take a look at the code and comments on how to do that here: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/ patheffects.py#L47 112 Chapter 4 Adding a shadow to the chart line To be able to distinguish one particular plot line in the figure or just to fit in the overall style of the output our figure is in, we sometimes need to add a shadow effect to the chart line (or histogram, for that matter). In this recipe we will be learning how to add a shadow
coordinate that the annotation relates to ff xybox: This defines the location of the annotation box ff xycoords: This defines what coordinating system is used by xy (for example, data coordinates) ff boxcoords: This defines what coordinating system is used by xybox (for example, offset from the xy location) ff pad: This specifies the amount of padding ff arrowprops: This is the dictionary of properties for drawing an arrow connection from an annotation-bounding box to a data point We