[Matplotlib-users] Creating custom markers as the union of complex vertices

rese eric.emsellem at eso.org
Wed Jul 12 11:22:15 EDT 2017


Hi

I have been looking for an elegant/simple (working!) solution to create new
complex markers for matplotlib.

For example, I would like to design a new marker which is the union of a set
of vertices, for example (just an example), two petals which are symmetric
(see verts1 and verts2) and two lines above and below (see verts3, and
verts4). I would also like to have the petal possibly filled (or not) and
the edgecolor of each vertices with possibly various colours (one petal is
blue, the other is orange). How should I proceed?

A naive way forward is to do something like (for a double petal, the left
one not being filled up, the right one being filled, see the definition for
verts1, verts2, verts3, verts4 below):

## Code
x = rand(10)
y = rand(10)
verts = [verts1, verts2, verts3, verts4]
fc = ['k', 'None', 'None', 'None']
ec = ['b', 'orange', 'k', 'k']

for lverts, lfc, lec in list(zip(verts, fc, ec)) :
     scatter(x, y, marker= (lverts, 0), facecolor=lfc, edgecolor=lec,
s=1000, label='My symbol')

==> HOWEVER, since these are done in a for loop, it is not considered as a
single marker when I do, for example, :

legend(loc=0)

QUESTION: how should I manage this? (couldn't find the answer on the net)

Suggestion are most welcome!

Thanks!
Eric
======================================
###### Definition for the vertices
if 1:
    # verts1:
    size, angrad = 10., 0.
    rx = 4. * size
    theta = np.linspace(-pi / 4., pi / 4., 151)
    x = rx*np.sqrt(cos(2.*theta))*cos(theta)
    y = rx*np.sqrt(cos(2.*theta))*sin(theta)
    rotx = x * cos(angrad) + y * sin(angrad)
    roty = -x * sin(angrad) + y * cos(angrad)
    verts1 = list(zip(rotx,roty))

    # verts2:
    size, angrad = 10.,  np.pi
    rx = 4. * size
    theta = np.linspace(-pi / 4., pi / 4., 151)
    x = rx*np.sqrt(cos(2.*theta))*cos(theta)
    y = rx*np.sqrt(cos(2.*theta))*sin(theta)
    rotx = x * cos(angrad) + y * sin(angrad)
    roty = -x * sin(angrad) + y * cos(angrad)
    verts2 = list(zip(rotx,roty))

    # verts3
    verts3 = list(zip([0.,0.],[0,0.1]))

    # verts4
    verts4 = list(zip([0.,0.],[-0.1,-0.03]))




--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Creating-custom-markers-as-the-union-of-complex-vertices-tp48083.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


More information about the Matplotlib-users mailing list