File:Polulation Pyramid Germany 2010.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 234 × 325 pixels, file size: 39 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description Polulation Pyramid Germany 2010
Date
Source Own work
Author Lennart Kudling
SVG development
InfoField
 
The SVG code is valid.
 
This vector image was created with Python.
 
The file size of this SVG image may be irrationally large because its text has been converted to paths inhibiting translations.
Source code
InfoField

Python code

#-*- coding: iso-8859-1 -*

# This Python program prints a LaTeX/TikZ document to stdout.
# Pipe the output of this script to a "foo.tex" file and afterwards call "pdflatex foo"
# The resulting "foo.pdf" file can be converted to SVG using
# http://www.tlhiv.org/MetaPost/tools/mptosvg/

# Data source:
# http://www.destatis.de/bevoelkerungspyramide/12kvb1w1.js
#
# 1950 + 60 = 2010
# popMale = popData[0][age][60]
# popFemale = popData[1][age][60]

data = \
    [
      (0, 341, 323)
    , (1, 350, 333)
    , (2, 353, 335)
    , (3, 348, 329)
    , (4, 353, 335)
    , (5, 363, 345)
    , (6, 364, 345)
    , (7, 370, 351)
    , (8, 379, 359)
    , (9, 395, 377)
    , (10, 398, 376)
    , (11, 406, 385)
    , (12, 419, 398)
    , (13, 412, 390)
    , (14, 399, 379)
    , (15, 406, 385)
    , (16, 422, 401)
    , (17, 433, 413)
    , (18, 451, 429)
    , (19, 498, 473)
    , (20, 497, 474)
    , (21, 515, 492)
    , (22, 508, 486)
    , (23, 502, 485)
    , (24, 490, 475)
    , (25, 490, 475)
    , (26, 496, 482)
    , (27, 511, 497)
    , (28, 509, 498)
    , (29, 515, 503)
    , (30, 490, 479)
    , (31, 484, 473)
    , (32, 481, 469)
    , (33, 474, 463)
    , (34, 464, 451)
    , (35, 470, 460)
    , (36, 476, 465)
    , (37, 524, 509)
    , (38, 581, 561)
    , (39, 609, 586)
    , (40, 657, 628)
    , (41, 689, 658)
    , (42, 706, 676)
    , (43, 726, 694)
    , (44, 734, 696)
    , (45, 745, 710)
    , (46, 740, 707)
    , (47, 714, 687)
    , (48, 700, 681)
    , (49, 680, 662)
    , (50, 658, 641)
    , (51, 624, 608)
    , (52, 610, 597)
    , (53, 592, 584)
    , (54, 572, 569)
    , (55, 558, 564)
    , (56, 538, 548)
    , (57, 537, 550)
    , (58, 525, 539)
    , (59, 527, 542)
    , (60, 509, 520)
    , (61, 467, 476)
    , (62, 436, 450)
    , (63, 379, 393)
    , (64, 331, 351)
    , (65, 438, 464)
    , (66, 443, 471)
    , (67, 427, 458)
    , (68, 510, 556)
    , (69, 529, 587)
    , (70, 511, 576)
    , (71, 468, 535)
    , (72, 427, 498)
    , (73, 403, 483)
    , (74, 377, 461)
    , (75, 338, 424)
    , (76, 262, 338)
    , (77, 248, 332)
    , (78, 240, 334)
    , (79, 238, 344)
    , (80, 216, 326)
    , (81, 199, 313)
    , (82, 166, 288)
    , (83, 142, 277)
    , (84, 122, 264)
    , (85, 95, 236)
    , (86, 80, 212)
    , (87, 73, 197)
    , (88, 63, 183)
    , (89, 51, 154)
    , (90, 31, 99)
    , (91, 16, 54)
    , (92, 12, 41)
    , (93, 10, 36)
    , (94, 10, 34)
    , (95, 9, 33)
    , (96, 6, 26)
    , (97, 4, 18)
    , (98, 2, 12)
    , (99, 1, 8)
    ]

# Find the maximums.
maxMale = 0
maxFemale = 0

for (_, popMale, popFemale) in data:

    if popMale > maxMale:
        maxMale = popMale
    if popFemale > maxFemale:
        maxFemale = popFemale

# Header
print \
    '\documentclass[a4paper,10pt]{article}\n' \
    '%\n' \
    '\usepackage{ngerman}\n' \
    '\usepackage{tikz}\n' \
    '\usepackage[active,tightpage]{preview}\n' \
    '\PreviewEnvironment{tikzpicture}\n' \
    '%\n' \
    '\usepackage[latin1]{inputenc}\n' \
    '\usepackage[T1]{fontenc}\n' \
    '\usepackage{fourier}\n' \
    '%\n' \
    '\\begin{document}\n' \
    '%\n' \
    '\\begin{tikzpicture}\n' \
    '%\n'

def yLabel(y, scale):
    realY = y * scale
    
    print '\\node at (%f,%f) {%i};' % (0.0, realY, y)

def yLines(offset, xScale, yScale, printMale, horizontalLines):
    if printMale:
        maxPop = maxMale
    else:
        maxPop = maxFemale
    
    for age in horizontalLines:
        
        x = maxPop * xScale + offset
        y = yScale * age
        
        print '\draw[color=white] (%f,%f) -- (%f,%f);' % (offset, y, x, y)

def halfPyramid(maleFemaleData, offset, xScale, yScale, printMale, doFill):
    
    if printMale:
        color = 'gray'
    else:
        color = 'gray!50'
    
    if doFill:
        print '\path[fill] (%f,0)[color=%s] --' % (offset, color)
    else:
        print '\draw [color=%s]' % color
    
    for (age, popMale, popFemale) in maleFemaleData:
        
        if age is not 0:
            print "--"
        
        if printMale:
            x = popMale
        else:
            x = popFemale
        
        yStart = yScale * age
        yEnd = yScale * (age + 1.0)
        
        xMaleStart = offset
        xMaleEnd = xScale * x + xMaleStart
        
        print '(%f,%f) -- (%f,%f)' % (xMaleEnd, yStart, xMaleEnd, yEnd)
    
    if doFill:
        print '(%f,%f) -- cycle;' % (offset, 100.0 * yScale)
    else:
        print ';'

xScale = 0.004
xMargin = 0.30
yScale = 0.08

halfPyramid(data, -xMargin, -xScale, yScale, True, True)
halfPyramid(data, xMargin, xScale, yScale, False, True)

pyramidLines = [20, 40, 60, 80]
yLines(-xMargin, -xScale, yScale, True, pyramidLines)
yLines(xMargin, xScale, yScale, False, pyramidLines)

halfPyramid(data, -xMargin, -xScale, yScale, False, False)
halfPyramid(data, xMargin, xScale, yScale, True, False)

for i in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
    yLabel(i, yScale)

print '\\node[anchor=south] at (0,%f) {Age};' % (105.0 * yScale)
print '\\node[anchor=west] at (%s,%f) {Men};' % (-maxMale * xScale - xMargin, 100.0 * yScale)
print '\\node[anchor=east] at (%s,%f) {Women};' % (maxFemale * xScale + xMargin, 100.0 * yScale)

# Footer
print \
    '%\n' \
    '\end{tikzpicture}\n' \
    '\end{document}\n'

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current17:03, 31 May 2010Thumbnail for version as of 17:03, 31 May 2010234 × 325 (39 KB)LennyWikipedia~commonswiki (talk | contribs){{Information |Description= |Source={{own}} |Date= |Author= Lenny222 |Permission= |other_versions= }}

The following page uses this file: