How to use the labels object tikzpy.lbl

Examples of how to use the labels object tikzpy.lbl.

Example 1 - Add labels to shapes and active or hide labels

See the following example:

../../_images/test_labels_01_add.tikz.png

Drawing created with the following tikzpy code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5import os, sys
 6
 7### Load main object
 8tikZ = py_tikZ.load()
 9
10### Create a cloud of points
11rows = 10
12columns = rows
13sep = 2
14
15
16for i in range(0,rows):
17
18    for j in range(0,columns):
19
20        x, y, z = j * sep, -i * sep, 0
21
22        p = tikZ.pto.pto(x, y, z, layer=0, alias='pto_%i_%i' % (i,j))
23
24        c = tikZ.shp.circle(p, sep/4., color = "yellow", fill = "green!20")
25
26        t = tikZ.shp.text(p, r'%i-%i' % (i,j))
27        t.zorder = 10
28
29        if i==j:
30            c.addlabel = "diagonal"
31            c.dellabel = "default"
32
33        if i+j==rows-1 and i!=j:
34            c.addlabel = "diagonal_sym"
35            c.dellabel = "default"
36
37### Hide diagonals
38tikZ.lbl.set_active_labels("diagonal", active=False)
39# Show acive labels
40print( tikZ.lbl.list_active_labels(active=True))
41
42### Change color symetric diagonal
43shps = tikZ.lbl.shapes_by_label("diagonal_sym")
44tikZ.shp.color_to_shapes(shps, "red")
45tikZ.shp.fill_to_shapes(shps, "brown!20")
46
47### Make drawing
48path = os.path.dirname(os.path.abspath(__file__))
49name = os.path.basename(os.path.abspath(__file__))
50name = os.path.splitext(name)[0]
51tikZ.save_pdf(path, name)

Example 2 - Add labels to shapes and active or hide labels. Treat them as groups.

See the following example:

../../_images/test_labels_02_add.tikz.png

Drawing created with the following tikzpy code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5import os, sys
 6
 7### Load main object
 8tikZ = py_tikZ.load()
 9
10### Create a cloud of points
11rows = 10
12columns = rows
13sep = 2
14
15### Declare groups
16grp1 = tikZ.grp.addgroup("_diagonal")
17grp2 = tikZ.grp.addgroup("_diagonal_sym")
18
19for i in range(0,rows):
20
21    for j in range(0,columns):
22
23        x, y, z = j * sep, -i * sep, 0
24
25        p = tikZ.pto.pto(x, y, z, layer=0, alias='pto_%i_%i' % (i,j))
26
27        c = tikZ.shp.circle(p, sep/4., color = "yellow", fill = "green!20")
28
29        t = tikZ.shp.text(p, r'%i-%i' % (i,j))
30        t.zorder = 10
31
32        if i==j:
33            grp1.add = [p,c,t]
34
35        if i+j==rows-1 and i!=j:
36            grp2.add = [p,c]
37
38
39
40### Hide diagonals
41tikZ.lbl.label_to_shapes(grp1.shps, "diagonal", delete_label=False)
42tikZ.lbl.label_to_shapes(grp1.shps, "default", delete_label=True)
43tikZ.lbl.set_active_labels("diagonal", active=False)
44# Show acive labels
45print( tikZ.lbl.list_active_labels(active=True) )   
46
47### Change color symetric diagonal
48tikZ.shp.color_to_shapes(grp2.shps, "red")
49tikZ.shp.fill_to_shapes(grp2.shps, "brown!20")
50
51### Make drawing
52path = os.path.dirname(os.path.abspath(__file__))
53name = os.path.basename(os.path.abspath(__file__))
54name = os.path.splitext(name)[0]
55tikZ.save_pdf(path, name)