Quick Success Data Science
Do you struggle with Matplotlib? If you’re a beginner, it may be because you haven’t taken the time to learn a few of its idiosyncrasies. If you suspect that’s the case, then do yourself a favor and read on! This won’t hurt or take too much time.
The open-source Matplotlib library dominates plotting in Python. It lets you generate quick and simple plots as well as elaborate, complex charts where you control every aspect of the display. Its popularity and maturity mean that you can always find helpful advice and useful code examples.
Like any powerful piece of software, Matplotlib can be, as one author put it, “syntactically tedious.” The simplest plots are easy, but the difficulty ramps up quickly. And even though resources like the Matplotlib gallery provide helpful code samples, if you want something slightly different than what’s provided, you might find yourself scratching your head.
In fact, many people use Matplotlib by copying and pasting other people’s code and then hacking at the edges until they get something they like. As a user once told me, “No matter how many times I use Matplotlib, it always feels like the first time!”
Fortunately, you can greatly alleviate this pain by taking the time to learn some key aspects of the package. So, in this article, we’ll focus on the nomenclature and plotting interfaces that can cause confusion. Armed with this knowledge, you may find Matplotlib a tool to embrace instead of one to avoid or use reluctantly.
Based on my experience learning Matplotlib, here are three issues that cause confusion:
- The somewhat awkward nomenclature used for plots.
- The co-existence of two plotting interfaces which I’ll call the pyplot approach and the object-oriented style.
- Plot manipulation methods in the two interfaces that have similar but different names.
Let’s take a look at these in turn.