Creating custom markers as the union of complex vertices

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating custom markers as the union of complex vertices

rese
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]))
Reply | Threaded
Open this post in threaded view
|

Re: Creating custom markers as the union of complex vertices

Sterling Smith
Search the internet for Proxy Artists in the legend.
-Sterling

----- Original Message -----
> From: "Eric Emsellem" <[hidden email]>
> To: [hidden email]
> Sent: Wednesday, July 12, 2017 8:18:28 AM
> Subject: [Matplotlib-users] Creating custom markers as the union of complex vertices

> 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]))
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users