source: trunk/years_matplotlib.xsl @ 164

Last change on this file since 164 was 150, checked in by pinsard, 12 years ago

first usage of matplotlib

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