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
About the Authors
About the Reviewer
Customer Feedback

Setting colors in Matplotlib

Many elements in a Matplotlib figure can have their colors specified. There are several ways to do so. You will come across the color parameter as a keyword argument for style settings very often in different functions. The alternate abbreviated keyword c can often be used. We will first briefly introduce the general rule here.

Single letters for basic built-in colors

There is a list of common colors we can quickly call with single letters:

  • b: Blue
  • g: Green
  • r: Red
  • c: Cyan
  • m: Magenta
  • y: Yellow
  • k: Black
  • w: White

Names of standard HTML colors

Examples are coralgoldspringgreendeepskyblue, and blueviolet. You can find the full list here:

RGB or RGBA color code

You can parse a tuple of three to four float numbers in the range of 0-1, such as (0.2,0.4,0.8) or (0.2,0.2,0.3,0.8). The first three numbers are RGB values that define the amount of red, green, and blue light to mix in the color. The optional fourth number is...