Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Matplotlib 3.0 Cookbook

You're reading from   Matplotlib 3.0 Cookbook Over 150 recipes to create highly detailed interactive visualizations using Python

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher Packt
ISBN-13 9781789135718
Length 676 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Nikhil Borkar Nikhil Borkar
Author Profile Icon Nikhil Borkar
Nikhil Borkar
Srinivasa Rao Poladi Srinivasa Rao Poladi
Author Profile Icon Srinivasa Rao Poladi
Srinivasa Rao Poladi
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Anatomy of Matplotlib FREE CHAPTER 2. Getting Started with Basic Plots 3. Plotting Multiple Charts, Subplots, and Figures 4. Developing Visualizations for Publishing Quality 5. Plotting with Object-Oriented API 6. Plotting with Advanced Features 7. Embedding Text and Expressions 8. Saving the Figure in Different Formats 9. Developing Interactive Plots 10. Embedding Plots in a Graphical User Interface 11. Plotting 3D Graphs Using the mplot3d Toolkit 12. Using the axisartist Toolkit 13. Using the axes_grid1 Toolkit 14. Plotting Geographical Maps Using Cartopy Toolkit 15. Exploratory Data Analysis Using the Seaborn Toolkit 16. Other Books You May Enjoy

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image