1 | <?xml version="1.0" encoding="iso-8859-1"?> |
---|
2 | <xsl:stylesheet |
---|
3 | version="1.0" |
---|
4 | xmlns:d="http://docbook.org/ns/docbook" |
---|
5 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
---|
6 | |
---|
7 | <!--rst |
---|
8 | |
---|
9 | .. _years_matplotlib.xsl: |
---|
10 | |
---|
11 | ==================== |
---|
12 | years_matplotlib.xsl |
---|
13 | ==================== |
---|
14 | |
---|
15 | DESCRIPTION |
---|
16 | =========== |
---|
17 | |
---|
18 | production d'un fichier de commande matplotlb avec données incorporées pour |
---|
19 | le graphe publications/année |
---|
20 | |
---|
21 | EXAMPLES |
---|
22 | ======== |
---|
23 | |
---|
24 | .. code-block:: sh |
---|
25 | |
---|
26 | xsltproc \-\-param makedate $((date)) \-\-param path "'.'" \-\-output ginette.py years_matplotlib.xsl biblio.xml |
---|
27 | python ginette.py |
---|
28 | open ++.png |
---|
29 | |
---|
30 | TODO |
---|
31 | ==== |
---|
32 | |
---|
33 | x time axe with yyyy labels |
---|
34 | |
---|
35 | add in makefile |
---|
36 | |
---|
37 | see http://matplotlib.sourceforge.net/examples/pylab_examples/demo_ribbon_box.html |
---|
38 | |
---|
39 | doctest |
---|
40 | |
---|
41 | EVOLUTIONS |
---|
42 | ========== |
---|
43 | |
---|
44 | $Id$ |
---|
45 | |
---|
46 | $URL$ |
---|
47 | |
---|
48 | - fplod 20120228 |
---|
49 | |
---|
50 | * add yticks and ylim |
---|
51 | * remove plot_shox to avoid interaction |
---|
52 | |
---|
53 | - fplod 20110627T144044Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
54 | |
---|
55 | * creation draft |
---|
56 | |
---|
57 | --> |
---|
58 | |
---|
59 | <xsl:output |
---|
60 | method="text" |
---|
61 | encoding="ISO-8859-1" |
---|
62 | indent="yes"/> |
---|
63 | |
---|
64 | <xsl:include href="biblioentry_xml.xsl"/> |
---|
65 | |
---|
66 | <xsl:variable name="list_years" select="///d:pubdate[not( self::node() = following::d:pubdate )]"/> |
---|
67 | |
---|
68 | <xsl:template match="d:bibliography"> |
---|
69 | """" |
---|
70 | |
---|
71 | EXAMPLES |
---|
72 | ======== |
---|
73 | |
---|
74 | .. code-block:: bash |
---|
75 | |
---|
76 | python years_matplotlib.py |
---|
77 | |
---|
78 | EVOLUTIONS |
---|
79 | ========== |
---|
80 | |
---|
81 | <xsl:value-of select="$makedate"/> |
---|
82 | |
---|
83 | """ |
---|
84 | |
---|
85 | import matplotlib.pyplot as plot |
---|
86 | import numpy as np |
---|
87 | import datetime |
---|
88 | |
---|
89 | fig = plot.figure() |
---|
90 | ax = fig.gca() |
---|
91 | |
---|
92 | # definition of axes |
---|
93 | ax.set_xlabel('Year') |
---|
94 | ax.set_ylabel('Nb of publications') |
---|
95 | # titre sur le graphique |
---|
96 | plot.title('nb of publications by year date : <xsl:value-of select="$makedate"/>') |
---|
97 | # |
---|
98 | |
---|
99 | dates=[] |
---|
100 | values=[] |
---|
101 | <!-- loop on years --> |
---|
102 | <xsl:for-each select="$list_years"> |
---|
103 | <xsl:sort order="ascending" data-type="number" select="."/> |
---|
104 | <xsl:call-template name="one_year"> |
---|
105 | <xsl:with-param name="year" select="."/> |
---|
106 | </xsl:call-template> |
---|
107 | </xsl:for-each> |
---|
108 | |
---|
109 | ax.set_ylim(min(values)-1, max(values)+1) |
---|
110 | ax.set_xlim(dates[0]-0.5, dates[-1]+0.5) |
---|
111 | plot.yticks(np.arange(min(values)-1,max(values)+1,1)) |
---|
112 | plot.bar(dates, values,width=0.5) |
---|
113 | |
---|
114 | # avoid overlap on labels |
---|
115 | fig.autofmt_xdate() |
---|
116 | # |
---|
117 | fig.savefig('<xsl:value-of select="$path"/>/years.png') |
---|
118 | |
---|
119 | </xsl:template> |
---|
120 | |
---|
121 | <xsl:template name="one_year"> |
---|
122 | <xsl:param name="year"/> |
---|
123 | dates.append(<xsl:value-of select="$year"/>) |
---|
124 | <xsl:text> </xsl:text> |
---|
125 | values.append(<xsl:value-of select="count(/descendant::d:biblioentry[child::d:biblioset[child::d:pubdate=$year]]) "/>) |
---|
126 | <xsl:text>
</xsl:text> |
---|
127 | </xsl:template> |
---|
128 | |
---|
129 | </xsl:stylesheet> |
---|