Python Data Visualization Cookbook - Second Edition

Python Data Visualization Cookbook - Second Edition

Language: English

Pages: 302

ISBN: 1784396699

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 to share your visualization online

In Detail

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.













Exporting data to JSON, CSV, and Excel While, as producers of data visualization, we are mostly using other people's data; importing and reading data are major activities. We do need to write or export data that we produced or processed, whether it is for our or others' current or future use. We will demonstrate how to use the previously mentioned Python modules to import, export, and write data to various formats such as JSON, CSV, and XLSX. For demonstration purposes, we are using the

locator classes. Here we are saying "set the major locator to be a multiple of 10": ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(10)) Tick formatters can similarly be specified. Formatters specify how the values (usually numbers) are displayed. For example, matplotlib.ticker.FormatStrFormatter simply specifies '%2.1f' or '%1.1f cm' as the string to be used as the label for the ticker. Let's take a look at one example using dates. 90 Chapter 3 matplotlib represents dates in

it... Here is one recipe that demonstrates how to plot polar bars: import numpy as np import as cm import matplotlib.pyplot as plt figsize = 7 colormap = lambda r: cm.Set2(r / 20.) N = 18 # number of bars fig = plt.figure(figsize=(figsize,figsize)) ax = fig.add_axes([0.2, 0.2, 0.7, 0.7], polar=True) theta = np.arange(0.0, 2*np.pi, 2*np.pi/N) 132 Chapter 4 radii = 20*np.random.rand(N) width = np.pi/4*np.random.rand(N) bars =, radii, width=width, bottom=0.0) for r, bar

more, apart from making the line a bit wider (2 pt). We proceed then to add one image for every measurement and to illustrate the number of pirates for a given year. For this we loop over the range of values of length (range(len(years))) , plotting one black point on each year/temperature coordinate: ax.plot(xy[0], xy[1], "ok") The image of the ship is loaded from file into a suitable array format using the read_png helper function: pirate = read_png('tall-ship.png') We then compute zoom

""" return page_template def main(): # Load data from CVS file afile = "median-dpi-countries.csv" datarows = [] with open(afile, 'r') as f: reader = csv.reader(f) 179 Plotting Charts with Images and Maps # skip header for row in reader: datarows.append(row) # Describe data description = {"country": ("string", "Country"), "dpi": ("number", "EUR"), } # Build list of dictionaries from loaded data data = [] for each in datarows: data.append({"country": each[0],

Download sample