The Four-Quadrant Chart
Learn how to create this classic chart with Python and matplotlib
The four-quadrant chart, or “business matrix” as it’s sometimes called, is widely used in a business setting. You’ve almost certainly seen one, and maybe you’ve even created one in your favorite plotting program. I was recently working on an analysis project in Python, and I decided a four-quadrant chart would be a great way to visualize my data. To my surprise, there’s no built-in function in matplotlib to crank one of these things out… so I set out to build one!
I’ll get to the details in a second. If you’re just after the plotting code, skip to the end.
First, you’ll need to import pandas , numpy, and matplotlib.pyplot as shown below:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
We’ll start off with a bare-bones implementation of the four-quadrant chart. This might be all you need if you’re going simple. Otherwise, you could use the following as a starting point and build out your own custom features.
A quick test to see how this works:
Here’s what we get:
Drop that code into a Jupyter Notebook and you’ll be well on your way to making super-slick charts. For those who want to get fancy, keep reading!
Data labels are one thing this chart could really benefit from. The basic chart you just saw does a great job showing the distribution of points, but it doesn’t give any information about what each point represents. That’s something we can fix by changing the code as follows:
This version of the chart is way more informative! I used single letters for my data labels so I could minimize the amount of clutter in the figure. The downside to this approach is that I need to display some kind of table that assigns meaning to each letter. I encourage you to get creative with how you display these labels. There might be a better way for your use case.
The final feature I’ll be adding to this chart provides a way to call attention to points in a specific quadrant or set of quadrants. This is a very useful feature because often, the audience will be most interested in points from one quadrant. In our example, the audience would probably be interested in quadrant two (upper-left) which contains low-cost, high-impact solutions. By decreasing the opacity of points outside the quadrant(s) of focus, we can draw attention to the points that really matter! I dropped the labels for non-focus points as well, but this is not something that makes sense in every use case.
Here’s the final plotting code in its entirety:
With the test code and output:
I hope you found this useful. Thanks for reading!