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

Drawing Subplots


In designing layouts of visual aids, it is often necessary to organize multiple relevant plots into panels in the same figure, such as when illustrating different aspects of the same dataset. Matplotlib provides a few ways to create figures with multiple subplots.

Initiating a figure with plt.figure()

The plt.figure() API is the API that is used to initiate a figure that serves as the base canvas. It takes in arguments that determines the number of figures and parameters such as size and background color of the plot image. It displays a new area as the canvas for plotting axes when called. We wouldn't obtain any graphical output unless we add other plotting elements. If we were to call plt.show() at this point, we would see a Matplotlib figure object being returned, as shown in the following screen capture:

When we are plotting simple figures that involve only a single plot, without the need for multiple panels, we can omit calling plt.figure(). If plt.figure() is not called...