Matplotlib 3.0 Cookbook
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

  1. 676 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul 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.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Matplotlib 3.0 Cookbook è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Matplotlib 3.0 Cookbook di Srinivasa Rao Poladi in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Data Processing. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2018
ISBN
9781789138665
Edizione
1

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...

Indice dei contenuti