r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""

2@file

3@brief Graphs on population

4"""

6import numpy

9def plot_population_pyramid(men, women, ax=None,

10 title="Population Pyramid",

11 xlabel="People",

12 ylabel="Age",

13 labels=('Men', 'Women', 'difference'),

14 **options):

15 """

16 create a population pyramid

18 @param men men (starting at 0)

19 @param women women (starting at 0)

20 @param ax existing ax to use or new ax if None

21 @param title graph title

22 @param xlabel x label

23 @param ylabel y label

24 @param labels series names

25 @param options options to create the graph if ax is None

26 @return ax

27 """

28 if ax is None:

29 from matplotlib import pyplot as plt

30 _, ax = plt.subplots(**options)

32 somme = men - women

33 ValH = ax.barh(numpy.arange(len(men)), men, 1.0, label=labels[

34 0], color='b', linewidth=0, align='center')

35 ValF = ax.barh(numpy.arange(len(women)), -women, 1.0,

36 label=labels[1], color='r', linewidth=0, align='center')

37 diff, = ax.plot(somme, numpy.arange(len(women)), 'y', linewidth=2)

38 ax.set_title(title)

39 ax.set_ylabel(ylabel)

40 ax.set_xlabel(xlabel)

41 ax.set_ylim([0, 110])

42 ax.legend((ValH[0], ValF[0], diff), labels)

43 return ax