source: qesdi/linplot/trunk/tests/linplot_tests/draw/draw_named_index.py @ 6446

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/linplot/trunk/tests/linplot_tests/draw/draw_named_index.py@6446
Revision 6446, 2.3 KB checked in by pnorton, 11 years ago (diff)

Made several changes to try and improve the layout of the plot. Also introduced rotating axis labels to avoid labels being drawn on top of each other.

Line 
1'''
2Created on 18 Dec 2009
3
4@author: pnorton
5'''
6import logging
7import math
8import os
9import numpy
10from linplot import Plot
11from linplot_tests.draw import getDrawOutputDir, SHORT_LOG_FORMAT_STRING
12
13from common import getData, seed
14import random
15log = logging.getLogger(__name__)
16
17def draw_named_index_short():
18   
19    fileName = 'named_index_short.png'
20    outputDir = getDrawOutputDir()
21    outputFile = os.path.join(outputDir, fileName)
22   
23    l = [ "scheme %s" % (x,) for x in ['F','E','D','C','B','A' ]]
24   
25   
26    ydata = numpy.array([230.0, 330.0, 650.0, 1600.0])
27    xdata = numpy.array(['scheme A', 'scheme B', 'scheme C', 'scheme D'])
28   
29    print type(xdata[0]), type(ydata[0])
30   
31    plt = Plot()
32   
33    # set the order of the labels to be used
34    plt.addXAxisIndexValues(l)
35   
36    plt.draw(xdata, ydata)
37   
38    ydata = numpy.array([1630.0, 730.0, 250.0, 100.0])
39    xdata = numpy.array(['scheme B', 'scheme C', 'scheme D', 'scheme E'])
40    plt.draw(xdata, ydata)
41   
42    ydata = numpy.array([100.0, 500.0, 50.0])
43    xdata = numpy.array(['scheme A', 'scheme E', 'scheme F'])
44    plt.draw(xdata, ydata)
45   
46   
47    plt.setXLabel('X - year')
48    plt.setYLabel('Y - temp')
49       
50    plt.saveImage(outputFile)
51    print "Wrote %s" % (outputFile)
52   
53def draw_named_index_long():
54   
55   
56    fileName = 'named_index_long.png'
57    outputDir = getDrawOutputDir()
58    outputFile = os.path.join(outputDir, fileName)
59   
60    l = [ "scheme with long name %s" % (x,) for x in ['A','B','C','D','E','F' ]]
61   
62    plt = Plot()
63    nlines = 3
64   
65    # set the order of the labels to be used
66    plt.addXAxisIndexValues(l)
67
68    for i in range(nlines):
69        nItems = random.randint(2, len(l))
70       
71        xdata = numpy.array(random.sample(l, nItems))
72        xdata.sort()
73        ydata = getData(len(xdata))
74        label="model number %s" % (i,)
75        log.debug("label= %s, xdata = %s, ydata = %s" % (label, xdata, ydata,))
76        plt.draw(xdata, ydata, label=label)
77       
78    plt.setXLabel('X - year')
79    plt.setYLabel('Y - temp')
80       
81    plt.saveImage(outputFile)
82    print "Wrote %s" % (outputFile)
83
84def draw_named_index(s=None):
85    seed(s)
86    draw_named_index_short()
87    draw_named_index_long()
88
89if __name__ == '__main__':
90   
91   
92    logging.basicConfig(level=logging.DEBUG, format=SHORT_LOG_FORMAT_STRING)
93    draw_named_index()
Note: See TracBrowser for help on using the repository browser.