Matplotlib 3.0 Cookbook
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

Compartir libro
  1. 676 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Build attractive, insightful, and powerful visualizations to gain quality insights from your data

Key Features

  • Master Matplotlib for data visualization
  • Customize basic plots to make and deploy figures in cloud environments
  • Explore recipes to design various data visualizations from simple bar charts to advanced 3D plots

Book Description

Matplotlib provides a large library of customizable plots, along with a comprehensive set of backends. Matplotlib 3.0 Cookbook is your hands-on guide to exploring the world of Matplotlib, and covers the most effective plotting packages for Python 3.7.

With the help of this cookbook, you'll be able to tackle any problem you might come across while designing attractive, insightful data visualizations. With the help of over 150 recipes, you'll learn how to develop plots related to business intelligence, data science, and engineering disciplines with highly detailed visualizations. Once you've familiarized yourself with the fundamentals, you'll move on to developing professional dashboards with a wide variety of graphs and sophisticated grid layouts in 2D and 3D. You'll annotate and add rich text to the plots, enabling the creation of a business storyline. In addition to this, you'll learn how to save figures and animations in various formats for downstream deployment, followed by extending the functionality offered by various internal and third-party toolkits, such as axisartist, axes_grid, Cartopy, and Seaborn.

By the end of this book, you'll be able to create high-quality customized plots and deploy them on the web and on supported GUI applications such as Tkinter, Qt 5, and wxPython by implementing real-world use cases and examples.

What you will learn

  • Develop simple to advanced data visualizations in Matplotlib
  • Use the pyplot API to quickly develop and deploy different plots
  • Use object-oriented APIs for maximum flexibility with the customization of figures
  • Develop interactive plots with animation and widgets
  • Use maps for geographical plotting
  • Enrich your visualizations using embedded texts and mathematical expressions
  • Embed Matplotlib plots into other GUIs used for developing applications
  • Use toolkits such as axisartist, axes_grid1, and cartopy to extend the base functionality of Matplotlib

Who this book is for

The Matplotlib 3.0 Cookbook is for you if you are a data analyst, data scientist, or Python developer looking for quick recipes for a multitude of visualizations. This book is also for those who want to build variations of interactive visualizations.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Matplotlib 3.0 Cookbook un PDF/ePUB en línea?
Sí, puedes acceder a Matplotlib 3.0 Cookbook de Srinivasa Rao Poladi en formato PDF o ePUB, así como a otros libros populares de Ciencia de la computación y Tratamiento de datos. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781789138665

Exploratory Data Analysis Using the Seaborn Toolkit

In this chapter, we will learn how to use one more third-party toolkit, seaborn, with the recipes that plot the following types of graphs:
  • Relational plots (sns.relplot):
    • Line plots (sns.lineplot)
    • Scatter plots (sns.scatterplot)
  • Categorical plots (sns.catplot):
    • Strip and swarm plots (sns.stripplot, sns.swarmplot)
    • Box and boxn plots (sns.boxplot, sns.boxnplot)
    • Bar and count plots (sns.barplot, sns.countplot)
    • Violin plots (sns.violinplot)
    • Point plots (sns.pointplot)
  • Distribution plots:
    • Distribution, Kernel Density Estimate (KDE), and rug plots (sns.distplot, sns.kdeplot, sns.rugplot)
  • Regression plots:
    • Regression plots and residual plots (sns.regplot, sns.residplot)
    • Lm plots (sns.lmplot)
  • Multi-plot grids:
    • Joint plots and joint grid plots (sns.jointplot, sns.JointGrid)
    • Pair Plots and pair grid plots (sns.pairplot, sns.PairGrid)
    • Facet grids (sns.FacetGrid)
  • Matrix plots:
    • Heatmaps (sns.heatmap)
    • Cluster maps (sns.clustermap)

Introduction

Seaborn is a powerful visualization tool built on top of Matplotlib. It makes multi-variable exploratory data analysis easier and intuitive, and it adds a few new types of plots, and its background styles and color maps are much more pleasing. It has many built-in statistical functions, making it a preferred tool for statistical data analysis. It also has quite elaborate online documentation, which you can find at https://seaborn.pydata.org/index.html.
We will use two datasets to demonstrate most of the seaborn features. One dataset, Wine Quality, is already familiar to you, and we will introduce a new dataset containing snack sales data from a fictitious snack shop. Instead of reading these files many times in each of the recipes, we will describe both of them in this section, and subsequently we will just use them for plotting the graphs. This is a slight deviation from the approach we have taken so far in this book. Both these data files can be found in the code library for this chapter.

Snacks Sales dataset

This dataset (provided in the code library) contains information on the sales of various items for a given date, day of the week, whether it is a weekend, and whether there was promotion on that day. We have data for three years: 2015, 2016, and 2017. The first five rows of the dataset look as follows:
Then, we will add two derived variables that help plot the required graphs:Month (1 to 12) and Quarter (1 to 4). After adding these variables, the first five rows look as follows:
The following code block reads the Excel file and adds additional variables:
import pandas as pd
import numpy as np

snacks_sales = pd.read_csv('Snacks_Data.csv')
snacks_sales['Month'] = pd.DatetimeIndex(snacks_sales['Date']).month
Quarter_Mapping = {1:1, 2:1, 3:1, 4:2, 5:2, 6:2, 7:3, 8:3, 9:3, 10:4,
11:4, 12:4}
snacks_sales['Quarter'] = snacks_sales['Month'].map(Quarter_Mapping)

Wine Quality

This dataset has 11 attributes that influence the quality of the wine. The Quality rating varies from 3 to 8, and then we map 3 and 4 to Low, 5 and 6 to Med, and 7 and 8 to High to create a new variable: Quality.
The first five rows of the dataset looks as follows:
We will also compute the correlation matrix for the Wine Quality dataset, which we will use in some of the plots.
The following is the code block to read and add additional variables to the Wine Quality dataset:
import pandas as pd

# Read the data from a csv file into pandas data frame
wine_quality = pd.read_csv('winequality.csv', delimiter=';')

# Map numeric Quality codes to "Low", "Med" and "High" qualitative
ratings
quality_map = {3:'Low', 4: 'Low', 5:'Med', 6:'Med', 7:'High', 8:'High'}
wine_quality['Quality'] = wine_quality['quality'].map(quality_map)

# compute correlation matrix
corr = wine_quality.corr()

# Display the first 5 records of wine_quality dataset, and unique
values of quality variable
wine_quality.head()
set(wine_quality.quality)

Semantic and facet variables

Apart from two variables whose relationship is plotted in a two-dimensional graph, seaborn allows the plotting of the influence of three additional variables on the relationship between the two main variables. These three variables are called semantic variables. They are referred to as hue, size, and style, which act as arguments to the given plot function.
For each unique value of hue, there will be one relationship plot; similarly, for each unique value of style, there will be one relationship plot. If there are two unique values in the hue variable (for example, Yes and No) and there are two unique values in the style variable (for example, s and D markers), then there will be 2 * 2 = 4 relationship plots (Yes & s, Yes & D, No & s, No & D combinations). Various hue values are plotted in different colors, and various style values are plotted in different line or marker styles.
Similarly, the size variable influences the size of the points being plotted for the two main variables. Unlike the Matplotlib scatter function, here, the size variable range is divided into multiple bins, and points are assigned to these bins. In the Matplotlib scatter function, each point is mapped to a different value in the size variable individually.
In addition to t...

Índice