Object-oriented graph creation using Artist objects
Up to this point, we have used Matplotlib's high-level functions, such as plot()
, to create graphs. In this section, we will show how to use objects of type Artist
to draw arbitrary shapes in a plot.
In Matplotlib, every plot element is an object from the Artist
class. There are two kinds of Artist
objects:
- Containers are objects designed to contain other graphic elements. The most important types of container are
Figure
andAxes
objects. - Primitives represent elements that can be directly drawn in a container. These include objects of type
Line2D
,Patch
, andText
, for example.
In the next recipe, we will see how to use Matplotilib's Artist
interface to draw general shapes in a figure.
Getting ready
Start Jupyter and run the following three commands in an execution cell:
%matplotlib inline import numpy as np import matplotlib.pyplot as plt
How to do it…
Enter the following code in a Jupyter execution cell and run it:
from matplotlib.patches import...