Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering Matplotlib 2.x
Mastering Matplotlib 2.x

Mastering Matplotlib 2.x: Effective Data Visualization techniques with Python

eBook
$9.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Matplotlib 2.x

Drawing on Plots

Till now, we have studied how to use style sheets to customize plot appearances, and how to tweak multi-panel plots to give more complex and appealing layouts for different kinds of plotting applications.

Matplotlib allows you to make plots that really show your own individual style. We will learn how to draw on plots to provide the viewer with visual guides that point them toward the important features of data. We will discuss adding horizontal and vertical lines, along with tweaking a background grid.

Versatile annotating adds arrows and some text to these arrows to the plots in order to customize the appearance of these annotations.

In this chapter, we will look at the following topics:

  • How to put lines in place
  • How to add text on plots
  • How to play with polygons and shapes
  • How to add different kinds of annotations
...

Putting lines in place

This section describes adding horizontal and vertical lines along with adding and tweaking a background grid.

Adding horizontal and vertical lines

We will begin by importing our required libraries, as shown:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150
  1. We will create the simple sine plot that we saw in Chapter 1, Heavy Customization, as follows:
# Adding a horizontal and vertical line
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))

We will get the following output:

  1. Now, to add an annotation, say, a line that splits...

Adding text on your plots

This section describes how we can add text to both the axis and figure objects, including adding text in multi-panel figures and configuring the appearance of text.

Adding text to both axis and figure objects

Let's start by importing everything we need:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150
  1. Next, bring up the standard sine curve that we have been using:
# Add some text
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))

We will get the following output:

  1. We will add some text, say, right in the middle...

Playing with polygons and shapes

This section talks about how to add polygons and other shapes and the different built-in shapes that Matplotlib provides.

Adding polygons and shapes to our plots

We will begin by importing what we need to from Matplotlib, as shown here:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))

We will use the same sign plot as in the earlier section, Adding text to both axis and figure objects. As shown in the following output, this is the most basic sine plot and no annotations...

Versatile annotating

We will import everything we need to bring up the simple sine plot:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150

Adding arrows to our plots with the annotate method

The annotate method has a lot of arguments, as seen in the following code:

# Add an arrow
nums = np.arange(0,10,0.1)
plt.plot(nums, np.sin(nums))
plt.annotate("", xy=(np.pi/2, 1), xytext=(5,0), arrowprops=dict(facecolor='k'))

The first argument in the preceding code is an empty string that will be displayed. xy tells us where the data coordinates...

Summary

In this chapter, we learned how to add lines, boxes, texts, different kinds of shapes, and polygons, as well as arrows in descriptions with annotate. We also focused on the viewer's attention on whatever kinds of data the plot is showing to make the insights.

In the next chapter, we will learn about special-purpose plots, which you can use for different kinds of data that haven't fallen into the sorts of plots we've seen so far.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Practical guide with hands-on examples to design interactive plots
  • Advanced techniques to constructing complex plots
  • Explore 3D plotting and visualization using Jupyter Notebook

Description

In this book, you’ll get hands-on with customizing your data plots with the help of Matplotlib. You’ll start with customizing plots, making a handful of special-purpose plots, and building 3D plots. You’ll explore non-trivial layouts, Pylab customization, and more about tile configuration. You’ll be able to add text, put lines in plots, and also handle polygons, shapes, and annotations. Non-Cartesian and vector plots are exciting to construct, and you’ll explore them further in this book. You’ll delve into niche plots and visualize ordinal and tabular data. In this book, you’ll be exploring 3D plotting, one of the best features when it comes to 3D data visualization, along with Jupyter Notebook, widgets, and creating movies for enhanced data representation. Geospatial plotting will also be explored. Finally, you’ll learn how to create interactive plots with the help of Jupyter. Learn expert techniques for effective data visualization using Matplotlib 3 and Python with our latest offering -- Matplotlib 3.0 Cookbook

Who is this book for?

This book is aimed at individuals who want to explore data visualization techniques. A basic knowledge of Matplotlib and Python is required.

What you will learn

  • Deal with non-trivial and unusual plots
  • Understanding Basemap methods
  • Customize and represent data in 3D
  • Construct Non-Cartesian and vector plots
  • Design interactive plots using Jupyter Notebook
  • Make movies for enhanced data representation

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 29, 2018
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781789618174
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 29, 2018
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781789618174
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 114.97
Mastering Matplotlib 2.x
$32.99
Applied Data Science with Python and Jupyter
$32.99
Matplotlib 3.0 Cookbook
$48.99
Total $ 114.97 Stars icon
Banner background image

Table of Contents

6 Chapters
Heavy Customization Chevron down icon Chevron up icon
Drawing on Plots Chevron down icon Chevron up icon
Special Purpose Plots Chevron down icon Chevron up icon
3D and Geospatial Plots Chevron down icon Chevron up icon
Interactive Plotting Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.