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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/linplot/trunk/tests/linplot_tests/draw/draw_legend_items.py@6446
Revision 6446, 1.5 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 15 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
13import random
14import time
15
16from linplot_tests.draw.common import getData, getLabel, seed
17   
18   
19def draw_small_legend_names(nlines=8):   
20    fileName = 'legend_small.png'
21    _drawLegend(fileName, nlines, 5, 10)
22   
23def draw_medium_legend_names(nlines=8):   
24    fileName = 'legend_med.png'
25    _drawLegend(fileName, nlines, 10, 20)
26   
27def draw_long_legend_names(nlines=8):   
28    fileName = 'legend_long.png'
29    _drawLegend(fileName, nlines, 20, 50)
30
31def _drawLegend(fname, nlines, legMin, legMax):
32
33    outputDir = getDrawOutputDir()
34    outputFile = os.path.join(outputDir, fname)
35   
36    xdata = numpy.array([x for x in range(0, 1000, 120)])
37   
38    plt = Plot()
39   
40    for i in range(nlines):
41        ydata = getData(len(xdata))
42        label = getLabel(legMin, legMax)
43       
44        plt.draw(xdata, ydata, label=label)
45   
46    plt.setXLabel('X - year')
47    plt.setYLabel('Y - temp')
48       
49    plt.saveImage(outputFile)
50    print "Wrote %s" % (outputFile)   
51   
52
53def draw_legend_items(s=None):
54   
55    seed(s)
56   
57    nlines = 8
58    draw_small_legend_names(nlines=nlines)
59    draw_medium_legend_names(nlines=nlines)
60    draw_long_legend_names(nlines=nlines)
61   
62
63if __name__ == '__main__':
64   
65    logging.basicConfig(level=logging.DEBUG, format=SHORT_LOG_FORMAT_STRING)
66    draw_data()
Note: See TracBrowser for help on using the repository browser.