source: trunk/years_matplotlib.xsl

Last change on this file was 355, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1<?xml version="1.0" encoding="iso-8859-1"?>
2<xsl:stylesheet
3version="1.0"
4xmlns:d="http://docbook.org/ns/docbook"
5xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6
7<!--rst
8
9.. _years_matplotlib.xsl:
10
11====================
12years_matplotlib.xsl
13====================
14
15DESCRIPTION
16===========
17
18production d'un fichier de commande matplotlb avec données incorporées pour
19le graphe publications/année
20
21EXAMPLES
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
30TODO
31====
32
33x time axe with yyyy labels
34
35add in makefile
36
37see http://matplotlib.sourceforge.net/examples/pylab_examples/demo_ribbon_box.html
38
39doctest
40
41EVOLUTIONS
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
71EXAMPLES
72========
73
74.. code-block:: bash
75
76   python years_matplotlib.py
77
78EVOLUTIONS
79==========
80
81<xsl:value-of select="$makedate"/>
82
83"""
84
85import matplotlib.pyplot as plot
86import numpy as np
87import datetime
88
89fig = plot.figure()
90ax = fig.gca()
91
92# definition of axes
93ax.set_xlabel('Year')
94ax.set_ylabel('Nb of publications')
95# titre sur le graphique
96plot.title('nb of publications by year date : <xsl:value-of select="$makedate"/>')
97#
98
99dates=[]
100values=[]
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
109ax.set_ylim(min(values)-1, max(values)+1)
110ax.set_xlim(dates[0]-0.5, dates[-1]+0.5)
111plot.yticks(np.arange(min(values)-1,max(values)+1,1))
112plot.bar(dates, values,width=0.5)
113
114# avoid overlap on labels
115fig.autofmt_xdate()
116#
117fig.savefig('<xsl:value-of select="$path"/>/years.png')
118
119</xsl:template>
120
121<xsl:template name="one_year">
122<xsl:param name="year"/>
123dates.append(<xsl:value-of select="$year"/>)
124<xsl:text> </xsl:text>
125values.append(<xsl:value-of select="count(/descendant::d:biblioentry[child::d:biblioset[child::d:pubdate=$year]]) "/>)
126<xsl:text>&#xA;</xsl:text>
127</xsl:template>
128
129</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.