5 Step Workflow To Touch Into the Heart of Matplotlib And Create Amazing Plots

Original Source Here

Containers and primitives

To get from the base artists to colorful plots, the components need to go through a long chain of inheritance of many MPL classes. Along this chain, two groups of classes are essential to how you use Matplotlib. These groups are called containers and primitives.

We’ve already seen two instances of containers — figures and axes. The figure contains axes, and axes contains pretty much everything.

Primitives are all the graphical or geometrical objects that go into a container. You rarely use these primitives directly. They are created dynamically when you call plotting functions. You can access all of their names under the patches module of Matplotlib:

As you can see, we have got everything we need to create histograms, scatterplots, boxplots, and line plots. They all can be made using patches like circles, rectangles, polygons, and lines.

You can find the whole image here from the docs.

From the above map of Matplotlib classes, we see the little Lind2D I mentioned earlier. It is a class that draws the lines and markers when we plot scatterplots and lines using plot or scatter functions.

Now, getting back to our plot — here are the steps we have made so far:

Let’s look at all artists within theax:

We see our lines. We also see four spines, which are also separate classes. The X and Y-axis objects are also visible along with the first element, which we haven’t seen before.

PathCollection represents the groups of dots. So, let’s extract it and give the dots a few customizations:

We increased the size a bit and gave the dots a red color with black edges,

Similarly, we can also tweak the spines:

A final trick I recommend is storing all created plots into a variable so that you can work on them separately without having to access them through axes:


Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: