Book Image

Matplotlib 3.0 Cookbook

By : Srinivasa Rao Poladi, Nikhil Borkar
Book Image

Matplotlib 3.0 Cookbook

By: Srinivasa Rao Poladi, Nikhil Borkar

Overview of this book

Matplotlib provides a large library of customizable plots, along with a comprehensive set of backends. Matplotlib 3.0 Cookbook is your hands-on guide to exploring the world of Matplotlib, and covers the most effective plotting packages for Python 3.7. With the help of this cookbook, you'll be able to tackle any problem you might come across while designing attractive, insightful data visualizations. With the help of over 150 recipes, you'll learn how to develop plots related to business intelligence, data science, and engineering disciplines with highly detailed visualizations. Once you've familiarized yourself with the fundamentals, you'll move on to developing professional dashboards with a wide variety of graphs and sophisticated grid layouts in 2D and 3D. You'll annotate and add rich text to the plots, enabling the creation of a business storyline. In addition to this, you'll learn how to save figures and animations in various formats for downstream deployment, followed by extending the functionality offered by various internal and third-party toolkits, such as axisartist, axes_grid, Cartopy, and Seaborn. By the end of this book, you'll be able to create high-quality customized plots and deploy them on the web and on supported GUI applications such as Tkinter, Qt 5, and wxPython by implementing real-world use cases and examples.
Table of Contents (17 chapters)

Twin axes

Sometimes, we may want to plot two charts on the same axes, but have a different scale of data. If we use a standard plot with the same scale on the left and right spines, charts may not look right due to a large difference in their scale of data. In such cases, we can use the twin axes feature provided by Matplotlib. We will learn how to use it in this recipe.

We will use product defects data for a month in a manufacturing plant for this example. We will draw a bar plot of the number of defects by reason code (for example 0 to 5, representing various reasons for producing defective products) and cumulative percentage line graph (sum total of defective products aggregated over reason codes).

There are three options for twinning the axes:

  • twinx: Shares the x axis for both the graphs, while the left and right axes denote two different scales
  • twiny: Shares the y axis for...