histogram

This commit is contained in:
Michael Fogleman 2018-02-19 18:01:28 -05:00
parent 61d82dbdc8
commit 0d0a2fa643
1 changed files with 442 additions and 0 deletions

442
examples/histogram.py Normal file
View File

@ -0,0 +1,442 @@
from __future__ import division
import axi
def main():
W = 8.5
H = 0.5
total = sum(x[1] for x in DATA)
lo = min(x[0] for x in DATA)
hi = max(x[0] for x in DATA)
peak = max(x[1] for x in DATA)
paths = []
path = []
for key, count in DATA:
x = W * (key - lo) / (hi - lo)
y = H * count / peak
path.append((x, -y))
if y > 0.01:
paths.append([(x, 0), (x, -y)])
paths.append(path)
paths.append([(0, 0), (W, 0)])
labels = [0, 1000, 2000, 3000, 3851]
for key in labels:
x = W * (key - lo) / (hi - lo)
paths.append([(x, 0.0), (x, 0.05)])
d = axi.Drawing(axi.text(str(key), axi.FUTURAL))
d = d.scale_to_fit_height(0.1)
d = d.move(x, 0.15, 0.5, 0)
paths.extend(d.paths)
title = 'Elevation Distribution (meters above sea level)'
d = axi.Drawing(axi.text(title, axi.FUTURAL))
d = d.scale_to_fit_height(0.15)
d = d.move(W / 2, 0.3, 0.5, 0)
paths.extend(d.paths)
d = axi.Drawing(paths)
d = d.rotate(180)
d = d.rotate_and_scale_to_fit(8.5, 8.5, step=90)
d = d.move(12, 8.5 / 2, 1, 0.5)
print d.bounds
d = d.sort_paths()
d = d.join_paths(0.01)
d = d.simplify_paths(0.001)
d.render().write_to_png('out.png')
d.dump('out.axi')
DATA = [
(0, 1860),
(10, 616),
(20, 13896),
(30, 7390),
(40, 17106),
(50, 17756),
(60, 19812),
(70, 20846),
(80, 26540),
(90, 32908),
(100, 30895),
(110, 30937),
(120, 34645),
(130, 39987),
(140, 50454),
(150, 43510),
(160, 45186),
(170, 46782),
(180, 48153),
(190, 53051),
(200, 56475),
(210, 67358),
(220, 66581),
(230, 62523),
(240, 63877),
(250, 65760),
(260, 69471),
(270, 68334),
(280, 64205),
(290, 65384),
(300, 67230),
(310, 70015),
(320, 74587),
(330, 79049),
(340, 84143),
(350, 88487),
(360, 92377),
(370, 100498),
(380, 86270),
(390, 82122),
(400, 80603),
(410, 84615),
(420, 92533),
(430, 89329),
(440, 86102),
(450, 87929),
(460, 86567),
(470, 82378),
(480, 81019),
(490, 79468),
(500, 76132),
(510, 76930),
(520, 72169),
(530, 70730),
(540, 72297),
(550, 72928),
(560, 75030),
(570, 77281),
(580, 78832),
(590, 80256),
(600, 82456),
(610, 83901),
(620, 82584),
(630, 84318),
(640, 82161),
(650, 80100),
(660, 79891),
(670, 80065),
(680, 77160),
(690, 72161),
(700, 69511),
(710, 67754),
(720, 65042),
(730, 63870),
(740, 64834),
(750, 64082),
(760, 61971),
(770, 61166),
(780, 60935),
(790, 59000),
(800, 57292),
(810, 56323),
(820, 56212),
(830, 56024),
(840, 62346),
(850, 59583),
(860, 57477),
(870, 56763),
(880, 56891),
(890, 54791),
(900, 55878),
(910, 54383),
(920, 54594),
(930, 54779),
(940, 54721),
(950, 54976),
(960, 54890),
(970, 54921),
(980, 54929),
(990, 55069),
(1000, 55110),
(1010, 55675),
(1020, 57084),
(1030, 58511),
(1040, 58725),
(1050, 59506),
(1060, 60498),
(1070, 62729),
(1080, 63675),
(1090, 64225),
(1100, 64607),
(1110, 65337),
(1120, 67527),
(1130, 65769),
(1140, 65712),
(1150, 65133),
(1160, 64530),
(1170, 65083),
(1180, 65451),
(1190, 64927),
(1200, 66665),
(1210, 68200),
(1220, 70238),
(1230, 72272),
(1240, 74862),
(1250, 77393),
(1260, 90007),
(1270, 89989),
(1280, 90317),
(1290, 89085),
(1300, 89867),
(1310, 89896),
(1320, 88303),
(1330, 88049),
(1340, 87744),
(1350, 88449),
(1360, 89547),
(1370, 90589),
(1380, 93502),
(1390, 93889),
(1400, 94315),
(1410, 95142),
(1420, 98384),
(1430, 99131),
(1440, 103998),
(1450, 102277),
(1460, 103992),
(1470, 106000),
(1480, 105960),
(1490, 109678),
(1500, 110972),
(1510, 110861),
(1520, 114622),
(1530, 119033),
(1540, 122392),
(1550, 121202),
(1560, 121773),
(1570, 124335),
(1580, 128502),
(1590, 130779),
(1600, 132780),
(1610, 135778),
(1620, 141292),
(1630, 141744),
(1640, 136584),
(1650, 140110),
(1660, 141461),
(1670, 139174),
(1680, 142406),
(1690, 150050),
(1700, 156269),
(1710, 157283),
(1720, 158085),
(1730, 158931),
(1740, 154644),
(1750, 155388),
(1760, 152779),
(1770, 151682),
(1780, 149647),
(1790, 144507),
(1800, 143324),
(1810, 144171),
(1820, 144580),
(1830, 141449),
(1840, 139113),
(1850, 135637),
(1860, 129574),
(1870, 124321),
(1880, 119062),
(1890, 114446),
(1900, 109406),
(1910, 105854),
(1920, 104861),
(1930, 102250),
(1940, 98704),
(1950, 97906),
(1960, 98738),
(1970, 98147),
(1980, 94073),
(1990, 88646),
(2000, 83503),
(2010, 81167),
(2020, 78390),
(2030, 73501),
(2040, 71495),
(2050, 68971),
(2060, 66484),
(2070, 64780),
(2080, 62488),
(2090, 59124),
(2100, 56963),
(2110, 55037),
(2120, 52282),
(2130, 50045),
(2140, 48638),
(2150, 46783),
(2160, 48194),
(2170, 46493),
(2180, 45299),
(2190, 44199),
(2200, 42657),
(2210, 41265),
(2220, 38577),
(2230, 36001),
(2240, 33838),
(2250, 31381),
(2260, 30262),
(2270, 28812),
(2280, 27107),
(2290, 25842),
(2300, 25865),
(2310, 25186),
(2320, 23732),
(2330, 21185),
(2340, 18564),
(2350, 17028),
(2360, 16239),
(2370, 15607),
(2380, 14477),
(2390, 13671),
(2400, 12906),
(2410, 12336),
(2420, 11296),
(2430, 10864),
(2440, 9934),
(2450, 9393),
(2460, 8790),
(2470, 8572),
(2480, 8408),
(2490, 8809),
(2500, 8465),
(2510, 8181),
(2520, 8110),
(2530, 8213),
(2540, 8098),
(2550, 7968),
(2560, 7695),
(2570, 7491),
(2580, 7294),
(2590, 6983),
(2600, 6874),
(2610, 6786),
(2620, 6471),
(2630, 6594),
(2640, 6591),
(2650, 6757),
(2660, 7133),
(2670, 7356),
(2680, 7262),
(2690, 6784),
(2700, 6326),
(2710, 6065),
(2720, 5742),
(2730, 5722),
(2740, 5833),
(2750, 6034),
(2760, 5777),
(2770, 5867),
(2780, 6003),
(2790, 5595),
(2800, 4554),
(2810, 3749),
(2820, 3102),
(2830, 2572),
(2840, 2097),
(2850, 1792),
(2860, 1535),
(2870, 1403),
(2880, 1244),
(2890, 1091),
(2900, 994),
(2910, 927),
(2920, 861),
(2930, 693),
(2940, 745),
(2950, 673),
(2960, 673),
(2970, 656),
(2980, 603),
(2990, 615),
(3000, 575),
(3010, 485),
(3020, 491),
(3030, 468),
(3040, 458),
(3050, 484),
(3060, 487),
(3070, 438),
(3080, 378),
(3090, 393),
(3100, 383),
(3110, 331),
(3120, 330),
(3130, 332),
(3140, 303),
(3150, 278),
(3160, 294),
(3170, 273),
(3180, 277),
(3190, 257),
(3200, 243),
(3210, 199),
(3220, 200),
(3230, 174),
(3240, 186),
(3250, 161),
(3260, 151),
(3270, 144),
(3280, 145),
(3290, 117),
(3300, 113),
(3310, 116),
(3320, 90),
(3330, 108),
(3340, 99),
(3350, 89),
(3360, 87),
(3370, 66),
(3380, 71),
(3390, 58),
(3400, 57),
(3410, 54),
(3420, 47),
(3430, 40),
(3440, 38),
(3450, 40),
(3460, 40),
(3470, 19),
(3480, 17),
(3490, 24),
(3500, 22),
(3510, 15),
(3520, 29),
(3530, 17),
(3540, 21),
(3550, 15),
(3560, 12),
(3570, 15),
(3580, 11),
(3590, 13),
(3600, 15),
(3610, 9),
(3620, 6),
(3630, 8),
(3640, 11),
(3650, 9),
(3660, 5),
(3670, 5),
(3680, 5),
(3690, 7),
(3700, 3),
(3710, 3),
(3720, 4),
(3730, 2),
(3740, 2),
(3750, 6),
(3760, 2),
(3770, 1),
(3780, 1),
(3790, 2),
(3800, 2),
(3810, 1),
(3820, 1),
(3830, 1),
(3840, 1),
(3851, 1),
]
if __name__ == '__main__':
main()