1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
|
% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\section{Style Sheets and Legends}
\label{section-dv-style-sheets}
\subsection{Overview}
In many data visualizations, different sets of data need to be visualized in a
single visualization. For instance, in a plot there might be a line for the
sine of~$x$ and another line for the cosine of~$x$; in another visualization
there might be a set of points representing data from a first experiment and
another set of points representing data from a second experiment; and so on. In
order to indicate to which data set a data point belongs, one might plot the
curve of the sine in, say, black, and the curve of the cosine in red; we might
plot the data from the fist experiment using stars and the data from the second
experiment using circles; and so on. Finally, at some place in the
visualization -- either inside the data or in a legend next to it -- the
meaning of the colors or symbols need to be explained.
Just as you would like \tikzname\ to map the data points automatically onto the
axes, you will also typically wish \tikzname\ to choose for instance the
coloring of the lines automatically for you. This is done using \emph{style
sheets}. There are at least two good reasons why you should prefer style sheets
over configuring the styling of each visualizer ``by hand'' using the |style|
key:
%
\begin{enumerate}
\item It is far more convenient to just say |style sheet=strong colors|
than having to individually picking the different colors.
\item The style sheets were chosen and constructed rather carefully.
For instance, the |strong colors| style sheet does not pick colors like
pure green or pure yellow, which have very low contrast with respect to
a white background and which often lead to unintelligible graphics.
Instead, opposing primary colors with maximum contrast on a white
background were picked that are visually quite pleasing.
Similarly, the different dashing style sheets are constructed in such a
way that there are only few and small gaps in the dashing so that no
data points get lost because the dashes are spaced too far apart. Also
dashing patterns were chosen that have a maximum optical difference.
As a final example, style sheets for plot marks are constructed in such
a way that even when two plot marks lie directly on top of each other,
they are still easily distinguishable.
\end{enumerate}
%
The bottom line is that whenever possible, you should use one of the predefined
style sheets rather than picking colors or dashings at random.
\subsection{Concepts: Style Sheets}
A \emph{style sheet} is a predefined list of styles such as a list of colors, a
list of dashing pattern, a list of plot marks, or a combinations thereof. A
style sheet can be \emph{attached} to a data point attribute. Then, the value
of this attribute is used with data points to choose which style in the list
should be chosen to visualize the data point.
In most cases, there is just one attribute to which style sheets get attached:
the |/data point/visualizer| attribute. The effect of attaching a style sheet
to this attribute is that each visualizer is styled differently.
For the following examples, let us first define a simple data set:
%
\begin{codeexample}[preamble={\usetikzlibrary{datavisualization.formats.functions}}]
\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};
\end{codeexample}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};}]
\tikz \datavisualization [
school book axes, all axes={unit length=7.5mm},
visualize as smooth line/.list={log, lin, squared, exp},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};}]
\tikz \datavisualization [
school book axes, all axes={unit length=7.5mm},
visualize as smooth line/.list={log, lin, squared, exp},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
\subsection{Concepts: Legends}
\label{section-dv-labels-in}
A \emph{legend} is a box that is next to a data visualization (or inside it at
some otherwise empty position) that contains a textual explanation of the
different colors or styles used in a data visualization.
Just as it is difficult to get colors and dashing patterns right ``by hand'',
it is also difficult to get a legend right. For instance, when a small line is
shown in the legend that represents the actual line in the data visualization,
if the line is too short and the dashing is too large, it may be impossible to
discern which dashing is actually meant. Similarly, when plot marks are shown
on such a short line, using a simple straight line may make it hard to read the
plot marks correctly.
The data visualization engine makes some effort to make it easy to create
high-quality legends. Additionally, it also offers ways of easily adding labels
for visualizers directly inside the data visualization, which is even better
than adding a legend, in general.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};}]
\tikz \datavisualization [
school book axes, all axes={unit length=7.5mm},
x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};}]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
every data set label/.append style={text colored},
log= {pin in data={text'=$\log x$, when=y is -1}},
lin= {pin in data={text=$x/2$, when=x is 2,
pin length=1ex}},
squared={pin in data={text=$x^2$, when=x is 1.1,
pin angle=230}},
exp= {label in data={text=$e^x$, when=x is -2}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\subsection{Usage: Style Sheets}
\subsubsection{Picking a Style Sheet}
To use a style sheet, you need to \emph{attach} it to an attribute. You can
attach multiple style sheets to an attribute and in this case all of these
style sheets can influence the appearance of the data points.
Most of the time, you will attach a style sheet to the |set| attribute. This
has the effect that each different data set inside the same visualization is
rendered in a different way. Since this use of style sheets is the most common,
there is a special, easy-to-remember option for this:
\begin{key}{/tikz/data visualization/style sheet=\meta{style sheet}}
Adds the \meta{style sheet} to the list of style sheets attached to the
|set| attribute.
%
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes, all axes={unit length=7.5mm},
visualize as smooth line/.list={log, lin, squared, exp},
style sheet=vary thickness and dashing,
style sheet=vary hue]
data group {function classes};
\end{codeexample}
%
\end{key}
While the |style sheet| key will attach a style sheet only to the |set|
attribute, the following key handler can be used to attach a style sheet to an
arbitrary attribute:
\begin{handler}{{.style sheet}=\meta{style sheet}}
Inside a data visualization you can use this key handler together with an
attribute, that is, with a key having the path prefix |/data point|. For
instance, in order to attach the \meta{style sheet} |strong colors| to the
attribute |set|, you could write
%
\begin{codeexample}[code only]
/data point/set/.style sheet=strong colors
\end{codeexample}
%
Indeed, the |style sheet| key is just a shorthand for the above.
The effect of attaching a style sheet is the following:
%
\begin{itemize}
\item A new object is created that will monitor the attribute.
\item Each time a special \emph{styling key} is emitted by the data
visualization engine, this object will inspect the current value of
the attribute to which it is attached.
\item Depending on this value, one of the styles stored in the style
sheet is chosen (how this works, exactly, will be explained in a
moment).
\item The chosen style is then locally applied.
\end{itemize}
In reality, things are a bit more complicated: If the attribute of the data
point happens to have a subkey named in the same way as the value, then the
value of is this subkey is used instead of the value itself. This allows
you to ``rename'' a value.
In a sense, a style sheet behaves much like a visualizer (see
Section~\ref{section-dv-visualizers}): In accordance with the value of a
certain attribute, the appearance of data points change. However, there are
a few differences: First, the styling of a data point needs to be triggered
explicitly and this triggering is not necessarily done for each data point
individually, but only for a whole visualizer. Second, styles can be
computed even when no data point is present. This is useful for instance in
a legend since, here, a visual representation of a visualizer needs to be
created independently of the actual data points.
\end{handler}
\subsubsection{Creating a New Style Sheet}
Creating a style sheet works as follows: For each possible value that an
attribute can attain we must specify a style. This is done by creating a style
key for each such possible value with a special path prefix and setting this
style key to the desired value. The special path prefix is
|/pgf/data visualization/style sheets| followed by the name of the style sheet.
As an example, suppose we wish to create a style sheet |test| that makes styled
data points |red| when the attribute has value |foo| and |green| when the
attribute has value |bar| and |dashed, blue| when the attribute is |foobar|. We
could then write
%
\begin{codeexample}[code only]
/pgf/data visualization/style sheets/test/foo/.style={red},
/pgf/data visualization/style sheets/test/bar/.style={green},
/pgf/data visualization/style sheets/test/foobar/.style={dashed, blue},
\end{codeexample}
We could then attach this style sheet to the attribute |code| as follows:
%
\begin{codeexample}[code only]
/data point/code/.style sheet=test
\end{codeexample}
Then, when |/data point/code=foobar| holds when the styling signal is raised,
the style |dashed, blue| will get executed.
A natural question arises concerning the situation that the value of the
attribute is not defined as a subkey of the style sheet. In this case, a
special key gets executed:
\begin{stylekey}{/pgf/data visualization/style sheets/\meta{style sheet}/default style=\meta{value}}
This key gets during styling whenever
|/pgf/data visualization/style sheet/|\meta{style sheet}|/|\meta{value} is
not defined.
\end{stylekey}
Let us put all of this together in a real-life example. Suppose we wish to
create a style sheet that makes the first data set |green|, the second |yellow|
and the third one |red|. Further data sets should be, say, |black|. The
attribute that we intend to style is the |set| attribute. For the moment, we
assume that the data sets will be named |1|, |2|, |3|, and so on (instead of,
say, |experiment 1| or |sin| or something more readable -- we will get rid of
this restriction in a minute).
We would now write:
%
\begin{codeexample}[preamble={\usetikzlibrary{datavisualization}}]
\pgfkeys{
/pgf/data visualization/style sheets/traffic light/.cd,
% All these styles have the above prefix.
1/.style={green!50!black},
2/.style={yellow!90!black},
3/.style={red!80!black},
default style/.style={black}
}
\tikz \datavisualization [
school book axes,
visualize as line=1,
visualize as line=2,
visualize as line=3,
style sheet=traffic light]
data point [x=0, y=0, set=1]
data point [x=2, y=2, set=1]
data point [x=0, y=1, set=2]
data point [x=2, y=1, set=2]
data point [x=0.5, y=1.5, set=3]
data point [x=2.25, y=1.75, set=3];
\end{codeexample}
In the above example, we have to name the visualizers |1|, |2|, |3| and so one
since the value of the |set| attribute is used both assign data points to
visualizers and also pick a style sheet. However, it would be much nicer if we
could name any way we want. To achieve this, we use the special rule for style
sheets that says that if there is a subkey of an attribute whose name is the
same name as the value, then the value of this key is used instead. This
slightly intimidating definition is much easier to understand when we have a
look at an example:
%
\pgfkeys{
/pgf/data visualization/style sheets/traffic light/.cd,
% All these styles have the above prefix.
1/.style={green!50!black},
2/.style={yellow!90!black},
3/.style={red!80!black},
default style/.style={black}
}
\begin{codeexample}[
preamble={\usetikzlibrary{datavisualization}},
pre={\pgfkeys{
/pgf/data visualization/style sheets/traffic light/.cd,
% All these styles have the above prefix.
1/.style={green!50!black},
2/.style={yellow!90!black},
3/.style={red!80!black},
default style/.style={black}
}},
]
% Definition of traffic light keys as above
\begin{tikzpicture}
\datavisualization data group {lines} = {
data point [x=0, y=0, set=normal]
data point [x=2, y=2, set=normal]
data point [x=0, y=1, set=heated]
data point [x=2, y=1, set=heated]
data point [x=0.5, y=1.5, set=critical]
data point [x=2.25, y=1.75, set=critical]
};
\datavisualization [
school book axes,
visualize as line=normal,
visualize as line=heated,
visualize as line=critical,
/data point/set/normal/.initial=1,
/data point/set/heated/.initial=2,
/data point/set/critical/.initial=3,
style sheet=traffic light]
data group {lines};
\end{tikzpicture}
\end{codeexample}
Now, it is a bit bothersome that we have to set all these |/data point/set/...|
keys by hand. It turns out that this is not necessary: Each time a visualizer
is created, a subkey of |/data point/set| with the name of the visualizer is
created automatically and a number is stored that is increased for each new
visualizer in a data visualization. This means that the three lines starting
with |/data point| are inserted automatically for you, so they can be left out.
However, you would need them for instance when you would like several different
data sets to use the same styling:
%
\begin{codeexample}[
preamble={\usetikzlibrary{datavisualization}},
pre={\pgfkeys{
/pgf/data visualization/style sheets/traffic light/.cd,
% All these styles have the above prefix.
1/.style={green!50!black},
2/.style={yellow!90!black},
3/.style={red!80!black},
default style/.style={black}
}%
\tikz \datavisualization data group {lines} = {
data point [x=0, y=0, set=normal]
data point [x=2, y=2, set=normal]
data point [x=0, y=1, set=heated]
data point [x=2, y=1, set=heated]
data point [x=0.5, y=1.5, set=critical]
data point [x=2.25, y=1.75, set=critical]
};},
]
% Definition of traffic light keys as above
\tikz \datavisualization [
school book axes,
visualize as line=normal,
visualize as line=heated,
visualize as line=critical,
/data point/set/critical/.initial=1, % same styling as first set
style sheet=traffic light]
data group {lines};
\end{codeexample}
We can a command that slightly simplifies the definition of style sheets:
\begin{command}{\pgfdvdeclarestylesheet\marg{name}\marg{keys}}
This command executes the \meta{keys} with the path prefix
|/pgf/data visualization/style sheets/|\penalty0\meta{name}. The above
definition of the traffic light style sheet could be rewritten as follows:
%
\begin{codeexample}[code only]
\pgfdvdeclarestylesheet{traffic light}{
1/.style={green!50!black},
2/.style={yellow!90!black},
3/.style={red!80!black},
default style/.style={black}
}
\end{codeexample}
%
\end{command}
As a final example, let us create a style sheet that changes the dashing
pattern according to the value of the attribute. We do not need to define an
large number of styles in this case, but can use the |default style| key to
``calculate'' the correct dashing.
\begin{codeexample}[
preamble={\usetikzlibrary{datavisualization}},
pre={\tikz \datavisualization data group {lines} = {
data point [x=0, y=0, set=normal]
data point [x=2, y=2, set=normal]
data point [x=0, y=1, set=heated]
data point [x=2, y=1, set=heated]
data point [x=0.5, y=1.5, set=critical]
data point [x=2.25, y=1.75, set=critical]
};},
]
\pgfdvdeclarestylesheet{my dashings}{
default style/.style={dash pattern={on #1pt off 1pt}}
}
\tikz \datavisualization [
school book axes,
visualize as line=normal,
visualize as line=heated,
visualize as line=critical,
style sheet=my dashings]
data group {lines};
\end{codeexample}
\subsubsection{Creating a New Color Style Sheet}
Creating a style sheet that varies colors according to an attribute works the
same way as creating a normal style sheet: Subkeys lies |1|, |2|, and so on use
the |style| attribute to setup a color. However, instead of using the |color|
attribute to set the color, you should use the |visualizer color| key to set
the color:
\begin{key}{/tikz/visualizer color=\meta{color}}
This key is used to set the color |visualizer color| to \meta{color}. This
color is used by visualizers to color the data they visualize, rather than
the current ``standard color''. The reason for not using the normal current
color is simply that it makes many internals of the data visualization
engine a bit simpler.
%
\begin{codeexample}[
preamble={\usetikzlibrary{datavisualization}},
pre={\tikz \datavisualization data group {lines} = {
data point [x=0, y=0, set=normal]
data point [x=2, y=2, set=normal]
data point [x=0, y=1, set=heated]
data point [x=2, y=1, set=heated]
data point [x=0.5, y=1.5, set=critical]
data point [x=2.25, y=1.75, set=critical]
};},
]
\pgfdvdeclarestylesheet{my colors}
{
default style/.style={visualizer color=black},
1/.style={visualizer color=black},
2/.style={visualizer color=red!80!black},
3/.style={visualizer color=blue!80!black},
}
\tikz \datavisualization [
school book axes,
visualize as line=normal,
visualize as line=heated,
visualize as line=critical,
style sheet=my colors]
data group {lines};
\end{codeexample}
%
\end{key}
There is an additional command that makes it easy to define a style sheet based
on a \emph{color series}. Color series are a concept from the |xcolor| package:
The idea is that we start with a certain color for the first data set and then
add a certain ``color offset'' for each next data point. Please consult the
documentation of the |xcolor| package for details.
\begin{command}{\tikzdvdeclarestylesheetcolorseries\marg{name}\marg{color model}\marg{initial color}\marg{step}}
This command creates a new style sheet using |\pgfdvdeclarestylesheet|.
This style sheet will only have a default style setup that maps numbers to
the color in the color series starting with \meta{initial color} and having
a stepping of \meta{step}. Note that when the value of the attribute is
|1|, which it is the first data set, the \emph{second} color in the color
series is used (since counting starts at |0| for color series). Thus, in
general, you need to start the \meta{initial color} ``one early''.
%
\begin{codeexample}[
preamble={\usetikzlibrary{datavisualization}},
pre={\tikz \datavisualization data group {lines} = {
data point [x=0, y=0, set=normal]
data point [x=2, y=2, set=normal]
data point [x=0, y=1, set=heated]
data point [x=2, y=1, set=heated]
data point [x=0.5, y=1.5, set=critical]
data point [x=2.25, y=1.75, set=critical]
};},
]
\tikzdvdeclarestylesheetcolorseries{greens}{hsb}{0.3,1.3,0.8}{0,-.4,-.1}
\tikz \datavisualization [
school book axes,
visualize as line=normal,
visualize as line=heated,
visualize as line=critical,
style sheet=greens]
data group {lines};
\end{codeexample}
%
\end{command}
\subsection{Reference: Style Sheets for Lines}
The following style sheets can be applied to visualizations that use the
|visualize as line| and related keys. For the examples, the following style and
data set are used:
%
\begin{codeexample}[code only]
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}
\end{codeexample}
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}
\begin{codeexample}[code only]
\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};
\end{codeexample}
\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};
\begin{stylesheet}{vary thickness}
This style varies the thickness of lines. It should be used only when there
are only two or three lines, and even then it is not particularly pleasing
visually.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=vary thickness]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\begin{stylesheet}{vary dashing}
This style varies the dashing of lines. Although it is not particularly
pleasing visually and although visualizations using this style sheet tend
to look ``excited'' (but not necessarily ``exciting''), this style sheet is
often the best choice when the visualization is to be printed in black and
white.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=vary dashing]
data group {sin functions};
\end{codeexample}
%
As can be seen, there are only seven distinct dashing patterns. The eighth
and further lines will use a solid line once more. You will then have to
specify the dashing ``by hand'' using the |style| option together with the
visualizer.
\end{stylesheet}
\begin{stylesheet}{vary thickness and dashing}
This style alternates between varying the thickness and the dashing of
lines. The difference to just using both the |vary thickness| and
|vary dashing| is that too thick lines are avoided. Instead, this style
creates clearly distinguishable line styles for many lines (up to 14) with
a minimum of visual clutter. This style is the most useful for
visualizations when many different lines (ten or more) should be printed in
black and white.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=vary thickness
and dashing]
data group {sin functions};
\end{codeexample}
%
For comparison, here is the must-less-than-satisfactory result of combining
the two independent style sheets:
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=vary thickness,
style sheet=vary dashing]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\subsection{Reference: Style Sheets for Scatter Plots}
The following style sheets can be used both for scatter plots and also with
lines. In the latter case, the marks are added to the lines.
\begin{stylesheet}{cross marks}
This style uses different crosses to distinguish between the data points of
different data sets. The crosses were chosen in such a way that when two
different cross marks lie at the same coordinate, their overall shape
allows one to still uniquely determine which marks are on top of each
other.
This style supports only up to six different data sets and requires the
|plotmarks| library.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as scatter/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=cross marks]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=cross marks]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\subsection{Reference: Color Style Sheets}
Color style sheets are very useful for creating visually pleasing data
visualizations that contain multiple data sets. However, there are two things
to keep in mind:
%
\begin{itemize}
\item At some point, every data visualization is printed or photo copied in
black and white by someone. In this case, data sets can often no longer
be distinguished.
\item A few people are color blind. They will not be able to distinguish
between red and green lines (and some people are not even able to
distinguish colors at all).
\end{itemize}
For these reasons, if there is any chance that the data visualization will be
printed in black and white at some point, consider combining color style sheets
with style sheets like |vary dashing| to make data sets distinguishable in all
situations.
\begin{stylesheet}{strong colors}
This style sheets uses pure primary colors that can very easily be
distinguished. Although not as visually pleasing as the |vary hue| style
sheet, the visualizations are easier to read when this style sheet is used.
Up to six different data sets are supported.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=strong colors]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=strong colors,
style sheet=vary dashing]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
Unlike |strong colors|, the following style sheets support, in principle, an
unlimited number of data set. In practice, as always, more than four or five
data sets lead to nearly indistinguishable data sets.
\begin{stylesheet}{vary hue}
This style uses a different hue for each data set.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=vary hue]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\begin{stylesheet}{shades of blue}
As the name suggests, different shades of blue are used for different data
sets.
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=shades of blue]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\begin{stylesheet}{shades of red}
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=shades of red]
data group {sin functions};
\end{codeexample}
\end{stylesheet}
\begin{stylesheet}{gray scale}
For once, this style sheet can also be used when the visualization is
printed in black and white.
%
\begin{codeexample}[
width=10cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
example visualization/.style={
scientific axes=clean,
y axis={ticks={style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2}}},
x axis={ticks={tick suffix=${}^\circ$}},
1={label in legend={text=$\frac{1}{6}\sin 11x$}},
2={label in legend={text=$\frac{1}{7}\sin 12x$}},
3={label in legend={text=$\frac{1}{8}\sin 13x$}},
4={label in legend={text=$\frac{1}{9}\sin 14x$}},
5={label in legend={text=$\frac{1}{10}\sin 15x$}},
6={label in legend={text=$\frac{1}{11}\sin 16x$}},
7={label in legend={text=$\frac{1}{12}\sin 17x$}},
8={label in legend={text=$\frac{1}{13}\sin 18x$}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list=
{1,2,3,4,5,6,7,8},
example visualization,
style sheet=gray scale]
data group {sin functions};
\end{codeexample}
%
\end{stylesheet}
\subsection{Usage: Labeling Data Sets Inside the Visualization}
In a visualization that contains multiple data sets, it is often necessary to
clearly point out which line or mark type corresponds to which data set. This
can be done in the main text via a sentence like ``the normal data (black) lies
clearly below the critical values (red)'', but it often a good idea to indicate
data sets ideally directly inside the data visualization or directly next to it
in a so-called legend.
The data visualization engine has direct support both for indicating data sets
directly inside the visualization and also for indicating them in a legend.
The ``best'' way of indicating where a data set lies or which color is used for
it is to put a label directly inside the data visualization. The reason this is
the ``best'' way is that people do not have to match the legend entries against
the data, let alone having to look up the meaning of line styles somewhere in
the text. However, adding a label directly inside the visualization is also the
most tricky way of indicating data sets since it is hard to compute good
positions for the labels automatically and since there needs to be some empty
space where the label can be put.
\subsubsection{Placing a Label Next to a Data Set}
The following key is used to create a label inside the data visualization for a
data set:
\begin{key}{/tikz/data visualization/visualizer options/label in data=\meta{options}}
This key is passed to a visualizer that has previously been created using
keys starting |visualize as ...|. It will create a label inside the data
visualization ``next'' to the visualizer (the details are explained in a
moment). You can use this key multiple times with a visualizer to create
multiple labels at different points with different texts.
The \meta{options} determine which text is shown and where it is shown.
They are executed with the following path prefix:
%
\begin{codeexample}[code only]
/tikz/data visualization/visualizer label options
\end{codeexample}
In order to configure which text is shown and where, use the following keys
inside the \meta{options}:
\begin{key}{/tikz/data visualization/visualizer label options/text=\meta{text}}
This is the text that will be displayed next to the data. It will be to
the ``left'' of the data, see the description below.
\end{key}
%
\begin{key}{/tikz/data visualization/visualizer label options/text'=\meta{text}}
Like |text|, only the text will be to the ``right'' of the data.
\end{key}
The following keys are used to configure where the label will be shown.
They use different strategies to specify one data point where the label
will be anchored. The coordinate of this data point will be stored in
|(label| |visualizer| |coordinate)|. Independently of the strategy, once
the data point has been chosen, the coordinate of the next data point is
stored in |(label| |visualizer| |coordinate')|. Then, a (conceptual) line
is created from the first coordinate to the second and a node is placed at
the beginning of this line to its ``left'' or, for the |text'| option, on
its ``right''. More precisely, an automatic anchor is computed for a node
placed implicitly on this line using the |auto| option or, for the |text'|
option, using |auto,swap|.
The node placed at the position computed in this way will have the
\meta{text} set by the |text| or |text'| option and its styling is
determined by the current |node style|.
Let us now have a look at the different ways of determining the data point
at which the label in anchored:
%
\begin{key}{/tikz/data visualization/visualizer label options/when=\meta{attribute}| is|\meta{number}}
This key causes the value of the \meta{attribute} to be monitored in
the stream of data points. The chosen is data point is the first data
point where the \meta{attribute} is at least \meta{number} (if this
never happens, the last data point is used).
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
log= {label in data={text'=$\log x$, when=y is -1,
text colored}},
lin= {label in data={text=$x/2$, when=x is 2}},
squared={label in data={text=$x^2$, when=x is 1.1}},
exp= {label in data={text=$e^x$, when=x is -2,
text colored}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\end{key}
%
\begin{key}{/tikz/data visualization/visualizer label options/index=\meta{number}}
This key chooses the \meta{number}th data point belonging to the
visualizer's data set.
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line/.list={exp},
exp= {label in data={text=$5$, index=5},
label in data={text=$10$, index=10},
label in data={text=$20$, index=20},
style={mark=x}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\end{key}
%
\begin{key}{/tikz/data visualization/visualizer label options/pos=\meta{fraction}}
This key chooses the first data point belonging to the data set whose
index is at least \meta{fraction} times the number of all data points
in the data set.
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line=exp,
exp= {label in data={text=$.2$, pos=0.2},
label in data={text=$.5$, pos=0.5},
label in data={text=$.95$, pos=0.95},
style={mark=x}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\end{key}
%
\begin{key}{/tikz/data visualization/visualizer label options/auto}
This key is executed automatically by default. It works like the |pos|
option, where the \meta{fraction} is set to $(\meta{data set's
index}-1/2)/\meta{number of data sets}$. For instance, when there are
$10$ data sets, the fraction for the first one will be $5\%$, the
fraction for the second will be $15\%$, for the third it will be
$25\%$, ending with $95\%$ for the last one.
The net effect of all this is that when there are several lines, labels
will be placed at different positions along the lines with hopefully
only little overlap.
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
]
\tikz \datavisualization [
scientific axes=clean,
visualize as smooth line/.list={linear, squared, cubed},
linear ={label in data={text=$2x$}},
squared={label in data={text=$x^2$}},
cubed ={label in data={text=$x^3$}}]
data [set=linear, format=function] {
var x : interval [0:1.5];
func y = 2*\value x;
}
data [set=squared, format=function] {
var x : interval [0:1.5];
func y = \value x * \value x;
}
data [set=cubed, format=function] {
var x : interval [0:1.5];
func y = \value x * \value x * \value x;
};
\end{codeexample}
%
As can be seen in the example, the result is not always satisfactory.
In this case, the |pin in data| option might be preferable, see below.
\end{key}
The following keys allow you to style labels.
\begin{key}{/tikz/data visualization/visualizer label options/node style=\meta{options}}
Just passes the options to |/tikz/data visualization/node style|.
\end{key}
%
\begin{key}{/tikz/data visualization/visualizer label options/text colored}
Causes the |node style| to set the text color to |visualizer color|.
The effect of this is that the label's text will have the same color as
the data set to which it is attached.
\end{key}
\begin{stylekey}{/tikz/data visualization/every data set label}
This style is executed with every label that represents a data set.
Inside this style, use |node style| to change the appearance of nodes.
This style has a default definition, usually you should just append
things to this style.
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
every data set label/.append style={text colored},
log= {label in data={text'=$\log x$, when=y is -1}},
lin= {label in data={text=$x/2$,
node style=sloped, when=x is 2}},
squared={label in data={text=$x^2$, when=x is 1.1}},
exp= {label in data={text=$e^x$,
node style=sloped, when=x is -2}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\end{stylekey}
\begin{stylekey}{/tikz/data visualization/every label in data}
Like |every data set label|, this key is also executed with labels.
However, this key is executed after the style sheets have been
executed, giving you a chance to overrule their styling.
\end{stylekey}
\end{key}
\subsubsection{Connecting a Label to a Data Set via a Pin}
\begin{key}{/tikz/data visualization/visualizer options/pin in data=\meta{options}}
This key is a variant of the |label in data| key and takes the same
options, plus two additional ones. The difference to |label in data| is
that the label node is shown a bit removed from the data set, but connected
to it via a small line (this is like the difference between the |label| and
|pin| options).
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
]
\tikz \datavisualization [
scientific axes=clean,
visualize as smooth line/.list={linear, squared, cubed},
linear ={pin in data={text=$2x$}},
squared={pin in data={text=$x^2$}},
cubed ={pin in data={text=$x^3$}}]
data [set=linear, format=function] {
var x : interval [0:1.5];
func y = \value x;
}
data [set=squared, format=function] {
var x : interval [0:1.5];
func y = \value x * \value x;
}
data [set=cubed, format=function] {
var x : interval [0:1.5];
func y = \value x * \value x * \value x;
};
\end{codeexample}
%
The following keys can be used additionally:
%
\begin{key}{/tikz/data visualization/visualizer label options/pin angle=\meta{angle}}
The position of the label of a |pin in data| is mainly computed in the
same way as for a |label in data|. However, once the position has been
computed, the label is shifted as follows:
%
\begin{itemize}
\item When an \meta{angle} is specified using the present key, the
shift is by the current value of |pin length| in the direction
of \meta{angle}.
\item When \meta{angle} is empty (which is the default), then the
shift is also by the current value of |pin length|, but now in
the direction that is orthogonal and to the left of the line
between the coordinate of the data point and the coordinate of
the next data point. When |text'| is used, the direction is to
the right instead of the left.
\end{itemize}
\end{key}
\begin{key}{/tikz/data visualization/visualizer label options/pin length=\meta{dimension}}
See the description of |pin angle|.
\end{key}
%
\begin{codeexample}[
width=6.3cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
school book axes,
x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
every data set label/.append style={text colored},
log= {pin in data={text'=$\log x$, when=y is -1}},
lin= {pin in data={text=$x/2$, when=x is 2,
pin length=1ex}},
squared={pin in data={text=$x^2$, when=x is 1.1,
pin angle=230}},
exp= {label in data={text=$e^x$, when=x is -2}},
style sheet=vary hue]
data group {function classes};
\end{codeexample}
\end{key}
\subsection{Usage: Labeling Data Sets Inside a Legend}
The ``classical'' way of indicating the style used for the different data sets
inside a visualization is a \emph{legend}. It is a description next to or even
inside the visualization that contains one line for each data set and displays
an iconographic version of the data set next to some text labeling the data
set. Note, however, that even though legend are quite common, also consider
using a |label in data| or a |pin in data| instead.
Creating a high-quality legend is by no means simple. A legend should not
distract the reader, so aggressive borders should definitively be avoided. A
legend should make it easy to match the actual styling of a data set (like,
say, using a red, dashed line) to the ``iconographic'' representation of this
styling. An example of what can go wrong here is using short lines to represent
lines dashed in different way where the lines are so short that the differences
in the dashing cannot be discerned. Another example is showing straight lines
with plot marks on them where the plot marks are obscured by the horizontal
line itself, while the plot marks are clearly visible in the actual
visualization since no horizontal lines occur.
The data visualization engine comes with a large set of options for creating
and placing high-quality legends next or inside data visualizations.
\subsubsection{Creating Legends and Legend Entries}
A data visualization can be accompanied by one or more legends. In order to
create a legend, the following key can be used (although, in practice, you will
usually use the |legend| key instead, see below):
\begin{key}{/tikz/data visualization/new legend=\meta{legend name} (default main legend)}
This key is used to create a new legend named \meta{legend name}. The
legend is empty by default and further options are needed to add entries to
it. When the key is called a second time for the same \meta{legend name}
nothing happens.
When a legend is created, a new key is created that can subsequently be
used to configure the legend:
%
\begin{key}{/tikz/data visualization/\meta{legend name}=\meta{options}}
When this key is used, the \meta{options} are executed with the path
prefix
%
\begin{codeexample}[code only]
/tikz/data visualization/legend options
\end{codeexample}
%
The different keys with this path prefix allow you to change the
position where the legend is shown and how it is organised (for
instance, whether legend entries are shown in a row or in a column or
in a square).
The different possible keys will be explained in the course of this
section.
\end{key}
In the end, the legend is just a \tikzname\ node, a |matrix| node, to be
precise. The following key is used to style this node:
\begin{key}{/tikz/data visualization/legend options/matrix node style=\meta{options}}
Adds the \meta{options} to the list of options that will be executed
when the legend's node is created.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={matrix node style={fill=black!25}},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
\end{key}
The following style allows you to configure the default appearance of every
newly created legend:
%
\begin{stylekey}{/tikz/data visualization/legend options/every new legend}
This key defaults to |east outside, label style=text right|. This means
that by default a legend is placed to the right of the data
visualization and that in the individual legend entries the text is to
the right of the data set visualization.
\end{stylekey}
%
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes, x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
new legend={upper legend},
new legend={lower legend},
upper legend=above,
lower legend=below,
log= {label in legend={text=$\log x$, legend=upper legend}},
lin= {label in legend={text=$x/2$, legend=upper legend}},
squared={label in legend={text=$x^2$, legend=lower legend}},
exp= {label in legend={text=$e^x$, legend=lower legend}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend=\meta{options}}
This is a shorthand for
|new legend=main legend, main legend=|\meta{options}. In other words, this
key creates a new |main legend| and immediately passes the configuration
\meta{options} to this legend.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes, x axis={label=$x$},
visualize as smooth line/.list={log, lin, squared, exp},
legend=below,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
%
\end{key}
As pointed out above, a legend is empty by default. In particular, the
different data sets are not automatically inserted into the legend. Instead,
the key |label in legend| must be used together with a data set:
\begin{key}{/tikz/data visualization/visualizer options/label in legend=\meta{options}}
This key is passed to a data set, similar to options like |pin in data| or
|smooth line|. The \meta{options} are used to configure the following:
%
\begin{itemize}
\item The legend in which the data set should be visualized.
\item The text that is to be shown in the legend for the data set.
\item The appearance of the legend entries.
\end{itemize}
%
In detail, the \meta{options} are executed with the path prefix
%
\begin{codeexample}[code only]
/tikz/data visualization/legend entry options
\end{codeexample}
%
To configure in which legend the label should appear, use the
following key:
%
\begin{key}{/tikz/data visualization/legend entry options/legend=\meta{name} (initially main legend)}
Set this key to the name of a legend that has previously been created
using |new legend|. The label will then be shown in this legend.
In most cases, there is only one legend (namely |main legend|) and
there is no need to set this key since it defaults to the main legend.
Also note that the legend \meta{name} is automatically created if it
nodes not yet exist.
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/text=\meta{text}}
Use this key to setup the \meta{text} that is shown as the label of the
data set.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes, x axis={label=$x$},
visualize as smooth line/.list=
{log, lin, squared, exp},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={pin in data ={text=$x^2$, pos=0.1}},
exp= {label in data ={text=$e^x$}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
\end{key}
In addition to the two keys described above, there are further keys that
are described in Section~\ref{section-dv-label-legend-entry-options}.
\end{key}
\subsubsection{Rows and Columns of Legend Entries}
In a legend, the different legend entries are arranged in a matrix, which
typically has only one row or one column. For the impatient reader: Say
|rows=1| to get everything in a row, say |columns=1| to get everything in a
single column, and skip the rest of this section.
The more patient reader will appreciate that when there are very many different
data sets in a single visualization, it may be necessary to use more than one
row or column inside the legend. \tikzname\ comes with a rather powerful
mechanism for distributing the multiple legend entries over the matrix.
The first thing to decide is in which ``direction'' the entries should be
inserted into the matrix. Suppose we have a $3 \times 3$ matrix and our entries
are $a$, $b$, $c$, and so on. Then, one might place the $a$ in the upper left
corner of the matrix, $b$ in the upper middle position, $c$ in the upper right
position, and $d$ in the middle left position. This is a ``first right, then
down'' strategy. A different strategy might be to place the $a$ in the upper
left corner, but $b$ in the middle left position, $c$ in the lower left
position, and $d$ then in the upper middle position. This is a ``first down,
then right'' strategy. In certain situations it might even make sense to place
$a$ in the lower right corner and then go ``first up, then left''.
All of these strategies are supported by the |legend| command. You can
configure which strategy is used using the following keys:
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}
\begin{key}{/tikz/data visualization/legend options/down then right}
Causes the legend entries to fill the legend matrix first downward and,
once a column is full, the next column is begun to the right of the
previous one. This is the default.
%
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={down then right, columns=3}]
data group {sin functions};
\end{codeexample}
%
In the example, the |legend example| is the following style:
%
\begin{codeexample}[code only]
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/down then left}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={down then left, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/up then right}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={up then right, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/up then left}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={up then left, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/left then up}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={left then up, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/left then down}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={left then down, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/right then up}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={right then up, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/right then down}
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={right then down, columns=3}]
data group {sin functions};
\end{codeexample}
\end{key}
Having configured the directions in which the matrix is being filled, you must
next setup the number of rows or columns that are to be shown. There are
actually two different ways of doing so. The first way is to specify a maximum
number of rows or columns. For instance, you might specify that there should be
at most ten rows to a column and when there are more, a new column should be
begun. This is achieved using the following keys:
\begin{key}{/tikz/data visualization/legend options/max rows=\meta{number}}
As the legend matrix is being filled, whenever the number of rows in the
current column would exceed \meta{number}, a new column is started.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={max rows=3}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={max rows=4}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={max rows=5}]
data group {sin functions};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/max columns=\meta{number}}
This key works like |max rows|, only now the number of columns is
monitored. Note that this strategy only really makes sense when the when
you use this key with a strategy that first goes left or right and then up
or down.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={right then down, max columns=2}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={right then down,max columns=3}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={right then down,max columns=4}]
data group {sin functions};
\end{codeexample}
%
\end{key}
The second way of specifying the number of entries in a row or column is to
specify an ``ideal number of rows or columns''. The idea is as follows: Suppose
that we use the standard strategy and would like to have everything in two
columns. Then if there are eight entries, the first four should go to the first
column, while the next four should go to the second column. If we have 20
entries, the first ten should go the first column and the next ten to the
second, and so on. So, in general, the objective is to distribute the entries
evenly so the this ``ideal number of columns'' is reached. Only when there are
too few entries to achieve this or when the number of entries per column would
exceed the |max rows| value, will the number of columns deviate from this ideal
value.
\begin{key}{/tikz/data visualization/legend options/ideal number of columns=\meta{number}}
Specifies, that the entries should be split into \meta{number} different
columns, whenever possible. However, when there would be more than the
|max rows| value of rows per column, more columns than the ideal number are
created.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={ideal number of columns=2}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={ideal number of columns=4}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={max rows=3,ideal number of columns=2}]
data group {sin functions};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/rows=\meta{number}}
Shorthand for |ideal number of rows=|\meta{number}.
\end{key}
\begin{key}{/tikz/data visualization/legend options/ideal number of rows=\meta{number}}
Works like |ideal number of columns|.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={ideal number of rows=2}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={ideal number of rows=4}]
data group {sin functions};
\end{codeexample}
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {sin functions} = {
data [format=function] {
var set : {1,...,8};
var x : interval [0:50];
func y = sin(\value x * (\value{set}+10))/(\value{set}+5);
}
};%
\tikzdatavisualizationset {
legend example/.style={
scientific axes, all axes={length=1cm, ticks=none},
1={label in legend={text=1}},
2={label in legend={text=2}},
3={label in legend={text=3}},
4={label in legend={text=4}},
5={label in legend={text=5}},
6={label in legend={text=6}},
7={label in legend={text=7}},
8={label in legend={text=8}}
}
}},
]
\tikz \datavisualization [
visualize as smooth line/.list={1,2,3,4,5,6,7,8},
legend example, style sheet=vary hue,
main legend={max columns=3,ideal number of rows=2}]
data group {sin functions};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/columns=\meta{number}}
Shorthand for |ideal number of columns=|\meta{number}.
\end{key}
\subsubsection{Legend Placement: The General Mechanism}
A legend can either be placed next to the data visualization or inside the data
visualization at some place where there are no data entries. Both approached
have advantages: Placing the legend next to the visualization minimises the
``cluttering'' by keeping all the extra information apart from the actual data,
while placing the legend inside the visualization minimises the distance
between the data sets and their explanations, making it easier for the eye to
connect them.
For both approaches there are options that make the placement easier, see
Sections \ref{section-dv-legend-outside} and~\ref{section-dv-legend-inside},
but these options internally just map to the following two options:
\begin{key}{/tikz/data visualization/legend options/anchor=\meta{anchor}}
The whole legend is a \tikzname-matrix internally. Thus, in particular, it
is stored in a node, which has anchors. Like for any other node, when the
node is shown, the node is shifted in such a way that the \meta{anchor} of
the node lies at the current |at| position.
\end{key}
\begin{key}{/tikz/data visualization/legend options/at=\meta{coordinate}}
Configures the \meta{coordinate} at which the \meta{anchor} of the legend's
node should lie.
It may seem hard to predict a good \meta{coordinate} for a legend since,
depending of the size of the axis, different positions need to the chosen
for the legend. However, it turns out that one can often use the
coordinates of the special nodes |data bounding box| and
|data visualization bounding box|, documented in
Section~\ref{section-dv-bounding-box}.
As an example, let us put a legend to the right of the visualization, but
so that the first entry starts at the top of the visualization:
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes, x axis={label=$x$},
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={anchor=north west, at=
(data visualization bounding box.north east)},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=vary dashing]
data group {function classes};
\end{codeexample}
%
As can be seen, a bit of an additional shift might have been in order, but
the result is otherwise quite satisfactory.
\end{key}
\subsubsection{Legend Placement: Outside to the Data Visualization}
\label{section-dv-legend-outside}
The following keys make it easy to place a legend outside the data
visualization.
\begin{key}{/tikz/data visualization/legend options/east outside}
Placing the legend to the right of the data visualization is the default:
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=east outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
\begin{key}{/tikz/data visualization/legend options/right}
This is an easier-to-remember alias.
\end{key}
\end{key}
\begin{key}{/tikz/data visualization/legend options/north east outside}
A variant, where the legend is to the right, but aligned with the northern
end of the data visualization:
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=north east outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/south east outside}
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=south east outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/west outside}
The legend is placed left. Note that the text also swaps its position.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=west outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\begin{key}{/tikz/data visualization/legend options/left}
This is an easier-to-remember alias.
\end{key}
\end{key}
\begin{key}{/tikz/data visualization/legend options/north west outside}
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=north west outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/south west outside}
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=south west outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
\end{key}
\begin{key}{/tikz/data visualization/legend options/north outside}
The legend is placed above the data. Note that the legend entries now for a
row rather than a column.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=north outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\begin{key}{/tikz/data visualization/legend options/above}
This is an easier-to-remember alias.
\end{key}
\end{key}
\begin{key}{/tikz/data visualization/legend options/south outside}
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=south outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\begin{key}{/tikz/data visualization/legend options/below}
This is an easier-to-remember alias.
\end{key}
\end{key}
\subsubsection{Legend Placement: Inside to the Data Visualization}
\label{section-dv-legend-inside}
There are two sets of options for placing a legend directly inside a data
visualization: First, there are options for placing it inside, but next to some
part of the border. Second, there are options for positioning it relative to a
coordinate given by a certain data point.
\begin{key}{/tikz/data visualization/legend options/south east inside}
Puts the legend in the upper right corner of the data.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin},
legend=south east inside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
Note that the text is now a little smaller since there tends to be much
less space inside the data visualization than next to it. Also, the
legend's node is filled in white by default to ensures that the legend is
clearly legible even in the presence of, say, a grid or data points behind
it. This behavior is triggered by the following style key:
\begin{stylekey}{/tikz/data visualization/legend options/every legend inside}
Executed the keys |opaque| by default and sets the text size to the
size of footnotes.
\end{stylekey}
\end{key}
In order to further configure the default appearance of an inner legend, the
following keys might be useful:
\begin{key}{/tikz/data visualization/legend options/opaque=\meta{color} (default white)}
When this key is used, the legend's node will be filled with the
\meta{color} and its corners will be rounded. Additionally, the inner and
outer separations will be set to sensible values.
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/transparent}
Sets the filling of the legend node to |none|.
\end{key}
The following keys work much the same way as |south east inside|:
\begin{key}{/tikz/data visualization/legend options/east inside}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/north east inside}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/south west inside}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/west inside}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/north west inside}
\end{key}
The keys |south inside| and |north inside| are a bit different: They use a row
rather than a column for the legend entries:
\begin{key}{/tikz/data visualization/legend options/south inside}
Puts the legend in the upper right corner of the data. Note that the text
is now a little smaller since there tends to be much less space inside the
data visualization than next to it.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list={log, lin},
legend=south inside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/north inside}
As above.
\end{key}
The above keys do not always give you as fine a control as you may need over
the placement of the legend. In such cases, the following keys may help (or you
can revert to directly setting the |at| and the |anchor| keys):
\begin{key}{/tikz/data visualization/legend options/at values=\meta{data point}}
This key allows you to specify the desired center of the legend in terms of
a data point. The \meta{data point} should be a list of comma-separated
key--value pairs that specify a data point. The legend will then be
centered at this data point.
%
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list={log, lin},
legend={at values={x=-1, y=2}},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend options/right of=\meta{data point}}
Works like |at values|, but the anchor is set to |west|:
%
\begin{codeexample}[
width=6cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list={log, lin},
legend={right of={x=-1, y=2}},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
The following keys work similarly:
%
\begin{key}{/tikz/data visualization/legend options/above right of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/above of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/above left of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/left of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/below left of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/below of=\meta{data point}}
\end{key}
%
\begin{key}{/tikz/data visualization/legend options/below right of=\meta{data point}}
\end{key}
\subsubsection{Legend Entries: General Styling}
\label{section-dv-label-legend-entry-options}
The entries in a legend can be styled in several ways:
%
\begin{itemize}
\item You can configure the styling of the text node.
\item You can configure the relative placement of the text node and the
little picture depicting the data set's styling.
\item You can configure how the data set's styling is depicted.
\end{itemize}
Before we have look at how each of these are configured, in detail, let us
first have a look at the keys that allow us to save a set of such styles:
\begin{stylekey}{/tikz/data visualization/every label in legend}
This key is executed with every label in a legend. However, the options
stored in this style are executed with the path prefix
|/tikz/data visualization/legend entry options|. Thus, this key can use
keys like |node style| to configure the styling of all text nodes:
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
every label in legend/.style={node style=
{fill=red!30}},
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=north east outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$,
node style={circle, draw=red}}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{stylekey}
\begin{key}{/tikz/data visualization/legend options/label style=\meta{options}}
This key can be used with a legend. It will simply add the \meta{options}
to the |every label in legend| style for the given legend.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={label style={node style=draw}},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$,
node style={circle, draw=red}}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\subsubsection{Legend Entries: Styling the Text Node}
The appearance of the text nodes is easy to configure.
\begin{key}{/tikz/data visualization/legend entry options/node style=\meta{options}}
This key adds \meta{options} to the styling of the text nodes of the label.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend=north east outside,
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$,
node style={circle, draw=red}}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/text colored}
Causes the |node style| to set the text color to |visualizer color|. The
effect of this is that the label's text will have the same color as the
data set to which it is attached.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={label style=text colored},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\subsubsection{Legend Entries: Text Placement}
Three keys govern where the text will be placed relative to the data set style
visualization.
\begin{key}{/tikz/data visualization/legend entry options/text right}
Placed the text node to the right of the data set style visualization. This
is the default for most, but not all, legends.
\end{key}
%
\begin{key}{/tikz/data visualization/legend entry options/text left}
Placed the text node to the left of the data set style visualization.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={label style=text left},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
%
\begin{key}{/tikz/data visualization/legend entry options/text only}
Shows only the text nodes and no data set style visualization at all. This
options only makes sense in conjunction with the |text colored| options,
which is why this options is also selected implicitly.
%
\begin{codeexample}[
width=8cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
pre={\tikz \datavisualization data group {function classes} = {
data [set=log, format=function] {
var x : interval [0.2:2.5];
func y = ln(\value x);
}
data [set=lin, format=function] {
var x : interval [-2:2.5];
func y = 0.5*\value x;
}
data [set=squared, format=function] {
var x : interval [-1.5:1.5];
func y = \value x*\value x;
}
data [set=exp, format=function] {
var x : interval [-2.5:1];
func y = exp(\value x);
}
};},
]
\tikz \datavisualization [
scientific axes,
visualize as smooth line/.list=
{log, lin, squared, exp},
legend={south east inside, rows=2,
label style=text only},
log= {label in legend={text=$\log x$}},
lin= {label in legend={text=$x/2$}},
squared={label in legend={text=$x^2$}},
exp= {label in legend={text=$e^x$}},
style sheet=strong colors]
data group {function classes};
\end{codeexample}
%
\end{key}
\subsubsection{Advanced: Labels in Legends and Their Visualizers}
\label{section-dv-legend-entries}
The following explanations are important only for you if you intend to create a
new visualizer and an accompanying label in legend visualizer; otherwise you
can safely proceed with the next section.
A legend entry consists not only of some explaining text, but, even more
importantly, of a visual representation of the style used for the data points,
created by a \emph{label in legend visualizer}. For instance, when data points
are visualized as lines in different colors, the legend entry for the first
line might consist of the text ``first experiment'' and a short line in black
and the second entry might consist of ``failed experiment'' and a short line in
red -- assuming, of course, that the style sheet makes the first line black and
the second line blue. As another example, when data sets are visualized as
clouds of plot marks, the texts in the legend would be accompanied by the plot
marks used to visualize the data sets.
For every visualizer, the \emph{label in legend visualizer} creates an
appropriate visualization of the data set's styling. There may be more than one
possible such label in legend visualizer that is appropriate, in which case
options are used to choose between them.
Let us start with the key for creating a new legend entry. This key gets called
for instance by |label in legend|:
\begin{key}{/tikz/data visualization/new legend entry=\meta{options}}
This key will add a new entry to the legend that is identified by the
\meta{options}. For this, the \meta{options} are executed once with the
path prefix |/tikz/data visualization/legend entry options| and the
resulting setting of the |legend| key is used to pick which legend the new
entry should belong to. Then, the \meta{options} are stored away for the
time being.
Later, when the legend is created, the \meta{options} get executed once
more. This time, however, the |legend| key is no longer important. Instead,
the \meta{options} that setup keys like |text| or |visualizer in legend|
now play a role.
In detail, the following happens:
%
\begin{itemize}
\item For the legend entry, a little cell picture is created in the
matrix of the legend (see Section~\ref{section-tikz-cell-pictures}
for details on cell pictures).
\item Inside this picture, a node is created whose text is taken from
the key
%
\begin{codeexample}[code only]
/tikz/data visualization/legend entry options/text
\end{codeexample}
%
\item Also inside the picture, the code stored in the following key
gets executed:
%
\begin{key}{/tikz/data visualization/legend entry options/visualizer in legend}
Set this key to some code that paints something in the cell
picture. Typically, this will be a visual representation of the
data set styling, but it could also be something different.
%
\begin{codeexample}[width=6cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
style sheet=vary dashing,
a={label in legend={text=a}},
new legend entry={
text=spacer,
visualizer in legend={\draw[solid] (0,0) circle[radius=2pt];}
},
b={label in legend={text=b}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
\end{key}
\end{itemize}
%
The following styles are applied in the following order before the cell
picture is filled:
%
\begin{enumerate}
\item |/tikz/data visualization/every data set label| with path
|/tikz/data visualization|
\item |/tikz/data visualization/every label in legend| with path\\
|/tikz/data visualization/legend entry options|.
\item The \meta{options}.
\item The code in the following key:
%
\begin{key}{/tikz/data visualization/legend entry options/setup}
Some code to be executed at this point. Mostly, it is used to
setup attributes for style sheets.
\end{key}
\item A styling signal is emitted.
\item Only for the node: The current value of |node style|.
\item Only for the visualizer in legend: The styling that has been
accumulated by calls to the following key:
%
\begin{stylekey}{/tikz/data visualization/legend entry options/visualizer in legend style=\\\marg{options}}
Calls to this key accumulate \meta{options} that will be
executed with the path prefix |/tikz| at this point.
\end{stylekey}
\end{enumerate}
\end{key}
As indicated earlier, the |new legend entry| key is called by the
|label in legend=|\meta{options} key internally. In this case, the following
extra \meta{extra options} are passed to |new legend entry| key:
%
\begin{itemize}
\item The styling of the visualizer.
\item The |/tikz/data visualization/every label in legend| style.
\item The |/tikz/every label| style with path |/tikz|.
\item Setting |setup| to |/data point/set=|\meta{name of the visualizer}.
\item The value of the |label legend options| that are stored in the
visualizer. These options can be changed using the following key:
%
\begin{key}{/tikz/data visualization/visualizer options/label in legend options=\meta{options}}
Use this key with a visualizer to configure the label in legend
options. Typically, this key is used only internally by a
visualizer upon its creating to set the \meta{options} to setup the
|visualizer in legend| key.
\end{key}
\end{itemize}
\subsubsection{Reference: Label in Legend Visualizers for Lines and Scatter Plots}
Visualizers like |visualize as line| or |visualize as smooth line| use a label
in legend visualizer that draws a short line to represent the data set inside
the legend. However, this line needs not be a simple straight line, but can be
a little curve or a small circle -- indeed, even the default line is not a
simple straight line but rather a small zig-zag curve. To configure this line,
the two keys are used, although you will only rarely use them directly, but
rather use one of the predefined styles mentioned later on.
Before we go into the glorious details of all of these keys, let us first have
a look at the keys you are most likely to use in practice: The keys for
globally reconfiguring the default label in legend visualizers:
%
\begin{stylekey}{/tikz/data visualization/legend entry options/default label in legend path}
This style is set, by default, to |zig zag label in legend line|. It is
installed by the styles |straight line|, |smooth line|, and |gap line|, so
changing this style will change the appearance of lines in legends. The
main other sensible option for this key is |straight label in legend line|.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
style sheet=vary dashing,
a={label in legend={text=a}}, b={label in legend={text=b}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
legend entry options/default label in legend path/.style=
straight label in legend line,
style sheet=vary dashing,
a={label in legend={text=a}}, b={label in legend={text=b}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
%
\end{stylekey}
%
\begin{stylekey}{/tikz/data visualization/legend entry options/default label in legend closed path}
This style is executed by |smooth cycle| and |straight cycle|. There are
(currently) no other predefined sets of coordinates that can be used
instead of the default value |circular label in legend line|.
\end{stylekey}
\begin{stylekey}{/tikz/data visualization/legend entry options/default label in legend mark}
This style is executed by |no lines| and, implicitly, by scatter plots. The
default is to use |label in legend line one mark|. Another possible value
is |label in legend line three marks|.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
visualize as scatter/.list={a,b,c},
style sheet=cross marks,
legend entry options/default label in legend mark/.style=
label in legend three marks,
a={label in legend={text=example a}},
b={label in legend={text=example b}},
c={label in legend={text=example c}}];
\end{codeexample}
%
\end{stylekey}
\begin{key}{/tikz/data visualization/legend entry options/label in legend line coordinates=\\\marg{list of coordinates}}
This key takes a \meta{list of coordinates}, which are
\tikzname-coordinates separated by commas like |(0,0),|\penalty0|(1,1)|.
The effect of setting the key is the following: The label in legend
visualizer used by, for instance, |visualize as line| will draw a path
going through these points. When the line is drawn, the exact same style
will be used as was used for the data set. For instance, if the
|smooth line| key was used and also the |style=red| key, the line through
the \meta{list of coordinates} will also be red and smooth. When the
|straight cycle| key was used, the coordinates will also be connected by a
cycle, and so on.
When the line connecting the \meta{list of coordinates} is drawn, the
coordinate system will have been shifted and transformed in such a way that
|(0,0)| lies to the left of the text and at half the height of the
character ``x''. This means that the right-most-point in the list should
usually be |(0,0)| and all other $x$-coordinates should usually be
negative. When the |text left| options is used, the coordinate system will
have been flipped, so the \meta{list of coordinates} is independent of
whether the text is to the right or to the left of the line.
Let us now have a look at a first, simple example. We create a legend entry
that is just a straight line, so it should start somewhere to the left of
the origin at height $0$ and go to the origin:
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
style sheet=vary dashing,
a={label in legend={text=a,
label in legend line coordinates={(-1em,0), (0,0)}}},
b={label in legend={text=b,
label in legend line coordinates={(-2em,0), (0,0)}}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
Now let us make this a bit more fancy and useful by using shifted lines:
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
legend={up then right}, style sheet=vary dashing,
a={label in legend={text=a,
label in legend line coordinates={(-2em,-.25ex), (0,0)}}},
b={label in legend={text=b,
label in legend line coordinates={(-2em,.25ex), (0,0)}}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
In the final example, we use a little ``hat'' to represent lines:
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
legend={up then right}, style sheet=vary dashing,
a={label in legend={text=a,
label in legend line coordinates={
(-2em,-.2ex), (-1em,.2ex), (0,-.2ex)}}},
b={label in legend={text=b,
label in legend line coordinates={
(-2em,-.2ex), (-1em,.2ex), (0,-.2ex)}}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/label in legend mark coordinates=\\\marg{list of coordinates}}
This key is similar to |label in legend line coordinates|, but now the
\meta{list of coordinates} is used as the positions where plot marks are
shown. Naturally, plot marks are only shown there if they are also shown by
the visualizer in the actual data -- just like the line through the
coordinates of the previous key is only shown when there is a line.
The \meta{list of coordinates} may be the same as the one used for lines,
but usually it is not. In general, it is better to have marks for instance
not at the ends of the line.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
school book axes, visualize as line/.list={a,b},
legend={up then right},
style sheet=vary dashing,
style sheet=cross marks,
a={label in legend={text=a,
label in legend line coordinates={
(-2em,-.2ex), (-1em,.2ex), (0,-.2ex)},
label in legend mark coordinates={
(-1em,.2ex)}}},
b={label in legend={text=b,
label in legend line coordinates={
(-2em,-.2ex), (-1em,.2ex), (0,-.2ex)},
label in legend mark coordinates={
(-2em,-.2ex), (0,-.2ex)}}}]
data point [x=-1, y=-1, set=a] data point [x=1, y=0, set=a]
data point [x=-1, y=1, set=b] data point [x=1, y=0.5, set=b];
\end{codeexample}
%
\end{key}
Naturally, you typically will not give coordinates explicitly for each label,
but use one of the following styles:
\begin{key}{/tikz/data visualization/legend entry options/straight label in legend line}
Just gives a straight line and two plot marks.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [visualize as line,
line={style={mark=x}, label in legend={text=example,
straight label in legend line}}];
\end{codeexample}
%
This style might seem like a good idea to use in general, but it does have
a huge drawback: Some commonly used plot marks will be impossible to
distinguish -- even though there is no problem distinguishing them in a
graph.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [visualize as line/.list={a,b,c},
legend entry options/default label in legend path/.style=
straight label in legend line,
a={style={mark=+}, label in legend={text=bad example a}},
b={style={mark=-}, label in legend={text=bad example b}},
c={style={mark=|}, label in legend={text=bad example c}}];
\end{codeexample}
%
For this reason, this option is not the default, but rather the next one.
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/zig zag label in legend line}
Uses a small up-down-up line as the label in legend visualizer. The two
plot marks are at the extremal points of the line. It works pretty well in
almost all situations and is the default.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
visualize as line=a,
visualize as smooth line/.list={b,c},
a={style={mark=+}, label in legend={text=better example a}},
b={style={mark=-}, label in legend={text=better example b}},
c={style={mark=|}, label in legend={text=better example c}}];
\end{codeexample}
%
Even though the above example shows that the marks are easier to
distinguish than with a straight line, the chosen marks are still not
optimal. This is the reason that the |cross marks| style uses different
crosses:
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [
visualize as line/.list={a,b},
visualize as smooth line=c,
style sheet=cross marks,
a={label in legend={text=good example a}},
b={label in legend={text=good example b}},
c={gap line, label in legend={text=good example c}}];
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/circular label in legend line}
This style is especially tailored to represent lines that are closed. It is
automatically selected for instance by the |polygon| or the |smooth cycle|
styles.
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
]
\tikz \datavisualization [
scientific axes={clean}, all axes={length=3cm},
visualize as line/.list={a,b,c},
a={polygon}, b={smooth cycle},
style sheet=cross marks,
a={label in legend={text=polygon}},
b={label in legend={text=circle}},
c={label in legend={text=line}}]
data [format=function, set=a] {
var t : {0,72,...,359};
func x = cos(\value t);
func y = sin(\value t);
}
data [format=function, set=b] {
var t : [0:2*pi];
func x = .8*cos(\value t r);
func y = .8*sin(\value t r);
}
data point [x=-1, y=0.5, set=c]
data point [x=1, y=0.25, set=c];
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/gap circular label in legend line}
This style is especially tailored to for the |gap cycle| style and
automatically selected by it:
%
\begin{codeexample}[
width=7cm,
preamble={\usetikzlibrary{datavisualization.formats.functions}},
]
\tikz \datavisualization [
scientific axes={clean}, all axes={length=3cm},
visualize as line/.list={a,b,c},
a={gap cycle}, b={smooth cycle}, c={gap line},
a={style={mark=*, mark size=0.5pt},
label in legend={text=polygon}},
b={label in legend={text=circle}},
c={style={mark=*, mark size=0.5pt, mark options=red},
label in legend={text=line}}]
data [format=function, set=a] {
var t : {0,72,...,359};
func x = cos(\value t);
func y = sin(\value t);
}
data [format=function, set=b] {
var t : [0:352];
func x = .8*cos(\value t);
func y = .8*sin(\value t);
}
data point [x=-1, y=0.5, set=c]
data point [x=1, y=0.25, set=c];
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/label in legend one mark}
To be used with scatter plots, since no line is drawn. Just displays a
single mark (this is the default with a scatter plot or when the |no line|
is selected.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [visualize as scatter/.list={a,b,c},
style sheet=cross marks,
a={label in legend={text=example a}},
b={label in legend={text=example b}},
c={label in legend={text=example c}}];
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/data visualization/legend entry options/label in legend three marks}
An alternative to the previous style, where several marks are shown.
%
\begin{codeexample}[width=5cm,preamble={\usetikzlibrary{datavisualization}}]
\tikz \datavisualization [visualize as scatter/.list={a,b,c},
style sheet=cross marks,
a={label in legend={text=example a, label in legend three marks}},
b={label in legend={text=example b, label in legend three marks}},
c={label in legend={text=example c, label in legend three marks}}];
\end{codeexample}
%
\end{key}
|