Creating your own markers
my_marker = mpath.Path(np.asarray((u,v)).T, codes)
Shapes are described by the movements of a cursor. We use the following three types of instructions:
MOVETO: This instruction will move the cursor to the specified coordinates; no line is drawn.
LINETO: This will move the cursor to the specified coordinates, while drawing a line.
CLOSEPOLY: It won't do anything, it will close the path. Your path will be concluded by this instruction.
# In[114]:
import numpy as np
import matplotlib.path as mpath
from matplotlib import pyplot as plt
# In[115]:
shape_description = [
( 1., 2., mpath.Path.MOVETO),
( 1., 1., mpath.Path.LINETO),
( 2., 1., mpath.Path.LINETO),
( 2., -1., mpath.Path.LINETO),
( 1., -1., mpath.Path.LINETO),
( 1., -2., mpath.Path.LINETO),
(-1., -2., mpath.Path.LINETO),
(-1., -1., mpath.Path.LINETO),
(-2., -1., mpath.Path.LINETO),
(-2., 1., mpath.Path.LINETO),
(-1., 1., mpath.Path.LINETO),
(-1., 2., mpath.Path.LINETO),
( 0., 0., mpath.Path.CLOSEPOLY),
]
# In[116]:
u, v, codes = zip(*shape_description)
#The constructor for the Path object takes a list of coordinates and a list of instructions as inputs
my_marker = mpath.Path(np.asarray((u,v)).T, codes)
data = np.random.rand(8,8)
plt.scatter(data[:,0], data[:,1], c='0.75', marker=my_marker, s=64)
plt.show()