Book Image

Matplotlib for Python Developers - Second Edition

By : Aldrin Yim, Claire Chung, Allen Yu
Book Image

Matplotlib for Python Developers - Second Edition

By: Aldrin Yim, Claire Chung, Allen Yu

Overview of this book

Python is a general-purpose programming language increasingly being used for data analysis and visualization. Matplotlib is a popular data visualization package in Python used to design effective plots and graphs. This is a practical, hands-on resource to help you visualize data with Python using the Matplotlib library. Matplotlib for Python Developers, Second Edition shows you how to create attractive graphs, charts, and plots using Matplotlib. You will also get a quick introduction to third-party packages, Seaborn, Pandas, Basemap, and Geopandas, and learn how to use them with Matplotlib. After that, you’ll embed and customize your plots in third-party tools such as GTK+3, Qt 5, and wxWidgets. You’ll also be able to tweak the look and feel of your visualization with the help of practical examples provided in this book. Further on, you’ll explore Matplotlib 2.1.x on the web, from a cloud-based platform using third-party packages such as Django. Finally, you will integrate interactive, real-time visualization techniques into your current workflow with the help of practical real-world examples. By the end of this book, you’ll be thoroughly comfortable with using the popular Python data visualization library Matplotlib 2.1.x and leveraging its power to build attractive, insightful, and powerful visualizations.
Table of Contents (16 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Preface

Python is a general-purpose programming language that's increasingly being used for data analysis and visualization. Matplotlib is a popular data visualization package in Python that's used to design effective plots and graphs. This book is a practical, hands-on resource to help you visualize data with Python using the Matplotlib library.

This book shows you how to create attractive graphs, charts, and plots using Matplotlib. You will also get a quick introduction to the third-party packages Seaborn, pandas, Basemap, and Geopandas, and learn how to use them with Matplotlib. After that, you'll embed and customize your plots in third-party tools such as GTK+, Qt 5, and WXWIDGETS.

You'll also be able to tweak the look and feel of your visualization with the help of the practical examples provided in this book. Further on, you'll explore Matplotlib 2.1.x on the web from a cloud-based platform using third-party packages such as Flask and Django. Finally, you will integrate interactive, real-time visualization techniques into your current workflow with the help of practical real-world examples.

By the end of this book, you'll be thoroughly comfortable with using the popular Python data visualization library Matplotlib 2.1.x, and leverage its power to build attractive, insightful, and powerful visualizations.

Who this book is for

This book is essentially for anyone who wants to create intuitive data visualizations using the Matplotlib library. If you're a data scientist or analyst and wish to create attractive visualizations using Python, you'll find this book useful. Some knowledge of Python programming is all you need to get started.

What this book covers

Chapter 1, Introduction to Matplotlib, gets you familiar with the capabilities and functionalities of Matplotlib.

Chapter 2, Getting Started with Matplotlib, gets you started with basic plotting techniques using Matplotlib syntax.

Chapter 3, Decorating Graphs with Plot Styles and Types, shows how to beautify your plots and select the right kind of plot that communicates your data effectively.

Chapter 4, Advanced Matplotlib, teaches you how to group multiple relevant plots into subplots in one figure using nonlinear scales, axis scales, plotting images, and advanced plots with the help of some popular third-party packages.

Chapter 5, Embedding Matplotlib in GTK+3, shows examples of embeding Matplotlib in applications using GTK+3.

Chapter 6,Embedding Matplotlib in Qt 5, explains how to embed a figure in a QWidget, use layout manager to pack a figure in a QWidget, create a timer, react to events, and update a Matplotlib graph accordingly. We use QT Designer to draw a simple GUI for Matplotlib embedding.

Chapter 7, Embedding Matplotlib in wxWidgets Using wxPython, shows how you can use Matplotlib in the wxWidgets framework, particularly using wxPython bindings.

Chapter 8, Integrating Matplotlib with Web Applications, teaches you how to develop a simple site that displays the price of Bitcoin. 

Chapter 9, Matplotlib in the Real World, begins our journey of understanding more advanced Matplotlib usage through real-world examples.

Chapter 10, Integrating Data Visualization into the Workflow, covers a mini-project combining the skills of data analytics with the visualization techniques you have learned.

To get the most out of this book

A working installation of Python 3.4 or later is required. The default Python distribution can be obtained from https://www.python.org/download/. The installation of packages is covered in the chapters, but you can refer to the official documentation pages for more details. A Windows 7+, macOS 10.10+, or Linux-based computer with 4 GB RAM or above is recommended.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Matplotlib-for-Python-Developers-Second-Edition/. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/MatplotlibforPythonDevelopersSecondEdition_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Another parameter for tuning is dash_capstyle."

A block of code is set as follows:

import matplotlib.pyplot as plt
plt.figure(figsize=(4,4))
x = [0.1,0.3]
plt.pie(x)
plt.show()

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

self.SetSize((500,550))self.button_1=wx.Button(self,wx.ID_ANY,"button_1")
##Code being added***self.Bind(wx.EVT_BUTTON,self.__updat_fun,self.button_1)#Setting up the figure, canvas and axes

Any command-line input or output is written as follows:

python3first_gtk_example.py

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select Qt in Files and Classes and Qt Designer Form in the middle panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.