9.1.2 Drawing Line Graphs

The plot_line_xy() routine provides a convenient tool for creating two-dimensional line graphs. Figure 9.5 shows the plot of inbreeding by birth year for the US Ayrshire cattle population. The plot is produced by the call:
pyp_db.loadPedigreeTable(ay)
coi_by_year = pyp_reports.meanMetricBy(ay,metric='fa',byvar='by')
cby = coi_by_year
del(cby[1900])
pyp_graphics.plot_line_xy(coi_by_year, gfilename='ay_coi_by_year',
    gtitle='Inbreeding coefficients for Ayrshire cows', gxlabel='Birth year',
    gylabel='Coefficient of inbreeding')
Figure 9.5: Average inbreeding by birth year for the US Ayrshire cattle population
The code above uses pyp_reports.meanMetricBy() (see ) to populate coi_by_year; the keys in coi_by_year are plotted in the x-axis, and the values are plotted on the y-axis. The default birth year, 1900, was deleted from the dictionary before the plot was drawn because leaving the default birthyear in the plot was distracting and somewhat misleading. The only restriction that you have to observe is that the value plotted on the y-ais has to be a numeric quantity.

If you need more complicated plots than are produced by plot_line_xy() you can write a new plotting function (Chapter 11) that uses the tools in matplotlib (http://matplotlib.sourceforge.net/). For complete details on the options taken by plot_line_xy please refer to the API documentation ().

See About this document... for information on suggesting changes.