Book Image

Matplotlib 2.x By Example

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

Matplotlib 2.x By Example

By: Allen Yu, Claire Chung, Aldrin Yim

Overview of this book

Big data analytics are driving innovations in scientific research, digital marketing, policy-making and much more. Matplotlib offers simple but powerful plotting interface, versatile plot types and robust customization. Matplotlib 2.x By Example illustrates the methods and applications of various plot types through real world examples. It begins by giving readers the basic know-how on how to create and customize plots by Matplotlib. It further covers how to plot different types of economic data in the form of 2D and 3D graphs, which give insights from a deluge of data from public repositories, such as Quandl Finance. You will learn to visualize geographical data on maps and implement interactive charts. By the end of this book, you will become well versed with Matplotlib in your day-to-day work to perform advanced data visualization. This book will guide you to prepare high quality figures for manuscripts and presentations. You will learn to create intuitive info-graphics and reshaping your message crisply understandable.
Table of Contents (15 chapters)
Title Page
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Adjusting text formats


For an informative figure, we typically have a number of text elements, including the title, labels of axes and ticks, legend, and any additional annotations. We can adjust the font size and font family in the default rc settings. These settings are set in a dictionary-like variable, matplotlib.rcParams, so you can do import matplotlib and define a parameter like this:

matplotlib.rcParams['font.size'] = 18 

Matplotlib also provides functions to alter the settings. The matplotlib.rc() changes the parameters one by one, whereas matplotlib.rcParams.update() accepts a dictionary input to change multiple settings simultaneously. Let's say we would like to change the font size to 20 and font family to serif, then use. We can do so in two ways:

matplotlib.rc('font', size=18)
matplotlib.rc('font', family='sans-serif')

This is equivalent to the following:

matplotlib.rcParams.update({'font.size': 18, 'font.family': 'serif'})

Font

Text with well-tuned fonts helps the data speak with...