Matplotlib 3.0 Cookbook
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

Buch teilen
  1. 676 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Matplotlib 3.0 Cookbook

Over 150 recipes to create highly detailed interactive visualizations using Python

Srinivasa Rao Poladi

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Matplotlib 3.0 Cookbook als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Matplotlib 3.0 Cookbook von Srinivasa Rao Poladi im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Data Processing. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

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

Inhaltsverzeichnis