General concepts of matplotlib

Posted by Bruce Liu on February 11, 2020

🏷️ Tags: python , matplotlib

Some concepts of a figure

Anatomy of a figure

Figure VS axes


The whole figure. The figure keeps track of all the child Axes, a smattering of ‘special’ artists (titles, figure legends, etc), and the canvas. A figure can have any number of Axes, but to be useful should have at least one.
A figure is everything in a final plot.


This is what you think of as ‘a plot’, it is the region of the image with the data space. A given figure can contain many Axes, but a given Axes object can only be in one Figure. The Axes contains two (or three in the case of 3D) Axis objects (be aware of the difference between Axes and Axis) which take care of the data limits (the data limits can also be controlled via set via the set_xlim() and set_ylim() Axes methods). Each Axes has a title (set via set_title()), an x-label (set via set_xlabel()), and a y-label set via set_ylabel()).
A axes concludes two (or three) axis, a x-label, a y-label, a title and the space surrounded by them.

Axes VS axis



These are the number-line-like objects. They take care of setting the graph limits and generating the ticks (the marks on the axis) and ticklabels (strings labeling the ticks). The location of the ticks is determined by a Locator object and the ticklabel strings are formatted by a Formatter. The combination of the correct Locator and Formatter gives very fine control over the tick locations and labels.
A axis concludes spines, ticks and ticklabels.


Share on:

« PREVIOUS: Plotting fonts when using matplotlib
NEXT: Remote desktop connection »