Creating your own markers

matplotlib offers a large variety of marker shapes. But you might not find something that suits your specific need. For instance, you might wish to use an animal silhouette, a company's logo, and so on. In this recipe, we are going to see how to define our own marker shapes.

How to do it...

matplotlib describes shapes as a path—a sequence of points linked together. Thus, to define our own marker shapes, we have to provide a sequence of points. In the following script example, we will define a cross-like shape:

import numpy as np import matplotlib.path as mpath from matplotlib import pyplot as plt shape_description = [ ( 1., 2., mpath.Path.MOVETO), ( 1., 1., mpath.Path.LINETO), ( 2., 1., mpath.Path.LINETO), ( 2., -1., mpath.Path.LINETO), ...

Get matplotlib Plotting Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.