~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/python/xw33.py

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8; -*-
 
2
# $Id: xw33.py 11717 2011-04-21 00:47:06Z airwin $
 
3
#  Copyright (C) 2010 Alan W. Irwin
 
4
 
 
5
#  Demonstrate most pllegend capability including unicode symbols.
 
6
 
 
7
#  This file is part of PLplot.
 
8
#
 
9
#  PLplot is free software; you can redistribute it and/or modify
 
10
#  it under the terms of the GNU Library General Public License as published
 
11
#  by the Free Software Foundation; either version 2 of the License, or
 
12
#  (at your option) any later version.
 
13
#
 
14
#  PLplot is distributed in the hope that it will be useful,
 
15
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#  GNU Library General Public License for more details.
 
18
#
 
19
#  You should have received a copy of the GNU Library General Public License
 
20
#  along with PLplot; if not, write to the Free Software
 
21
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
22
#
 
23
#  This example designed just for devices (e.g., the cairo-related and
 
24
#  qt-related devices) where the best choice of glyph is automatically
 
25
#  selected by the related libraries (pango/cairo or Qt4) for each
 
26
#  unicode character depending on what system fonts are installed.  Of
 
27
#  course, you must have the appropriate TrueType fonts installed to
 
28
#  have access to all the required glyphs.
 
29
 
 
30
from plplot_py_demos import *
 
31
 
 
32
position_options = [
 
33
PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
 
34
PL_POSITION_TOP | PL_POSITION_OUTSIDE,
 
35
PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_OUTSIDE,
 
36
PL_POSITION_RIGHT| PL_POSITION_OUTSIDE,
 
37
PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
 
38
PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
 
39
PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE,
 
40
PL_POSITION_LEFT | PL_POSITION_OUTSIDE,
 
41
PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_INSIDE,
 
42
PL_POSITION_TOP | PL_POSITION_INSIDE,
 
43
PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_INSIDE,
 
44
PL_POSITION_RIGHT| PL_POSITION_INSIDE,
 
45
PL_POSITION_RIGHT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
 
46
PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
 
47
PL_POSITION_LEFT | PL_POSITION_BOTTOM | PL_POSITION_INSIDE,
 
48
PL_POSITION_LEFT | PL_POSITION_INSIDE,
 
49
]
 
50
 
 
51
# Pick 5 arbitrary UTF-8 symbols useful for plotting points (✠✚✱✪✽✺✰✴✦).
 
52
special_symbols = [
 
53
"✰",
 
54
"✴",
 
55
"✱",
 
56
"✽",
 
57
"✦",
 
58
]
 
59
 
 
60
def plcolorbar_example_1( bar_type, ticks, sub_ticks, values, title ):
 
61
    pladv( 0 )
 
62
    # Setup color palette 1
 
63
    plspal1( "cmap1_blue_red.pal", 1 )
 
64
 
 
65
    n = len(values)
 
66
    color_step = 1.0 / float(n - 1)
 
67
    colors = color_step*arange(n)
 
68
 
 
69
    opt = PL_POSITION_LEFT | bar_type | PL_COLORBAR_LABEL_LEFT | PL_COLORBAR_CAP_HIGH
 
70
 
 
71
    if bar_type & PL_COLORBAR_SHADE_LABEL:
 
72
        axis_opts_1 = "iv"
 
73
        axis_opts_2 = "i"
 
74
    else:
 
75
        if sub_ticks != 0:
 
76
            axis_opts_1 = "stv"
 
77
            axis_opts_2 = "st"
 
78
        else:
 
79
            axis_opts_1 = "tv"
 
80
            axis_opts_2 = "t"
 
81
 
 
82
    plcolorbar( opt, 0.1, 0.1, 0.5, 0.1,
 
83
                ticks, sub_ticks,
 
84
                axis_opts_1, "Test label - Left, High Cap",
 
85
                colors, values )
 
86
 
 
87
    opt = PL_POSITION_RIGHT | bar_type | PL_COLORBAR_LABEL_RIGHT | PL_COLORBAR_CAP_LOW
 
88
 
 
89
    plcolorbar( opt, 0.1, 0.4, 0.5, 0.1,
 
90
                ticks, sub_ticks,
 
91
                axis_opts_1, "Test label - Right, Low Cap",
 
92
                colors, values )
 
93
 
 
94
    opt = PL_POSITION_TOP | bar_type | PL_COLORBAR_LABEL_TOP | PL_COLORBAR_CAP_HIGH
 
95
 
 
96
    plcolorbar( opt, 0.1, 0.1, 0.5, 0.1,
 
97
                ticks, sub_ticks,
 
98
                axis_opts_2, "Test label - Upper, High Cap",
 
99
                colors, values )
 
100
 
 
101
    opt = PL_POSITION_BOTTOM | bar_type | PL_COLORBAR_LABEL_BOTTOM | PL_COLORBAR_CAP_LOW
 
102
 
 
103
    plcolorbar( opt, 0.4, 0.1, 0.5, 0.1,
 
104
                ticks, sub_ticks,
 
105
                axis_opts_2, "Test label - Lower, Low Cap",
 
106
                colors, values )
 
107
 
 
108
    plvpor( 0.0, 1.0, 0.0, 1.0 )
 
109
    plwind( 0.0, 1.0, 0.0, 1.0 )
 
110
    plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title )
 
111
 
 
112
def plcolorbar_example_2( bar_type, ticks, sub_ticks, values, title ):
 
113
    pladv( 0 )
 
114
    # Setup color palette 1
 
115
    plspal1( "cmap1_blue_yellow.pal", 1 )
 
116
 
 
117
    n = len(values)
 
118
    color_step = 1.0 / float(n - 1)
 
119
    colors = color_step*arange(n)
 
120
    opt = PL_POSITION_LEFT | bar_type | PL_COLORBAR_LABEL_LEFT | PL_COLORBAR_CAP_LOW
 
121
 
 
122
    if bar_type == PL_COLORBAR_SHADE_LABEL:
 
123
        axis_opts_1 = ""
 
124
        axis_opts_2 = ""
 
125
    else:
 
126
        if sub_ticks != 0:
 
127
            axis_opts_1 = "stv"
 
128
            axis_opts_2 = "st"
 
129
        else:
 
130
            axis_opts_1 = "tv"
 
131
            axis_opts_2 = "t"
 
132
 
 
133
    plcolorbar( opt, 0.1, 0.1, 0.5, 0.1,
 
134
                ticks, sub_ticks,
 
135
                axis_opts_1, "Test label - Left, Low Cap",
 
136
                colors, values )
 
137
 
 
138
    opt = PL_POSITION_RIGHT | bar_type | PL_COLORBAR_LABEL_RIGHT | PL_COLORBAR_CAP_HIGH
 
139
 
 
140
    plcolorbar( opt, 0.1, 0.4, 0.5, 0.1,
 
141
                ticks, sub_ticks,
 
142
                axis_opts_1, "Test label - Right, High Cap",
 
143
                colors, values )
 
144
 
 
145
    opt = PL_POSITION_TOP | bar_type | PL_COLORBAR_LABEL_TOP | PL_COLORBAR_CAP_LOW
 
146
 
 
147
    plcolorbar( opt, 0.1, 0.1, 0.5, 0.1,
 
148
                ticks, sub_ticks,
 
149
                axis_opts_2, "Test label - Upper, Low Cap",
 
150
                colors, values )
 
151
 
 
152
    opt = PL_POSITION_BOTTOM | bar_type | PL_COLORBAR_LABEL_BOTTOM | PL_COLORBAR_CAP_HIGH
 
153
 
 
154
    plcolorbar( opt, 0.4, 0.1, 0.5, 0.1,
 
155
                ticks, sub_ticks,
 
156
                axis_opts_2, "Test label - Lower, High Cap",
 
157
                colors, values )
 
158
 
 
159
    plvpor( 0.0, 1.0, 0.0, 1.0 )
 
160
    plwind( 0.0, 1.0, 0.0, 1.0 )
 
161
    plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title )
 
162
 
 
163
def main():
 
164
    # First page illustrating the 16 standard positions.
 
165
    pladv(0)
 
166
    plvpor(0.25, 0.75, 0.25, 0.75)
 
167
    plwind(0.0, 1.0, 0.0, 1.0)
 
168
    plbox("bc", 0.0, 0, "bc", 0.0, 0)
 
169
    plsfont(PL_FCI_SANS, -1, -1)
 
170
    plmtex("t", 8.0, 0.5, 0.5, "The 16 standard legend positions with")
 
171
    plmtex("t", 6.0, 0.5, 0.5, "the same (0.05) offset in x and y")
 
172
 
 
173
    # Set up legend arrays with the correct size, type.
 
174
    nlegend = 1
 
175
    opt_array = zeros(nlegend, "int")
 
176
    text_colors = zeros(nlegend, "int")
 
177
    text = zeros(nlegend, "S200")
 
178
    box_colors = zeros(nlegend, "int")
 
179
    box_patterns = zeros(nlegend, "int")
 
180
    box_scales = zeros(nlegend)
 
181
    box_line_widths = zeros(nlegend, "int")
 
182
    line_colors = zeros(nlegend, "int")
 
183
    line_styles = zeros(nlegend, "int")
 
184
    line_widths = zeros(nlegend, "int")
 
185
    symbol_colors = zeros(nlegend, "int")
 
186
    symbol_scales = zeros(nlegend)
 
187
    symbol_numbers = zeros(nlegend, "int")
 
188
    symbols = zeros(nlegend, "S100")
 
189
 
 
190
    # Only specify legend data that are required according to the
 
191
    # value of opt_array for that entry.
 
192
    opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX
 
193
    opt_array[0] = PL_LEGEND_LINE | PL_LEGEND_SYMBOL
 
194
    line_styles[0] = 1
 
195
    line_widths[0] = 1
 
196
    symbol_scales[0] = 1.
 
197
    symbol_numbers[0] = 4
 
198
    symbols[0] = "*"
 
199
 
 
200
    # Use monotype fonts so that all legends are the same size.
 
201
    plsfont(PL_FCI_MONO, -1, -1)
 
202
    plscol0a( 15, 32, 32, 32, 0.70 )
 
203
 
 
204
    for k in range(16):
 
205
        position = position_options[k]
 
206
        opt = opt_base
 
207
        text[0] = "%2.2d" % k
 
208
        text_colors[0] = 1 + (k % 8)
 
209
        line_colors[0] = 1 + (k % 8)
 
210
        symbol_colors[0] = 1 + (k % 8)
 
211
 
 
212
        (legend_width, legend_height) = \
 
213
        pllegend( opt, position, 0.05, 0.05,
 
214
                  0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0,
 
215
                  1., text_colors, text,
 
216
                  box_colors, box_patterns, box_scales, box_line_widths,
 
217
                  line_colors, line_styles, line_widths,
 
218
                  symbol_colors, symbol_scales, symbol_numbers, symbols )
 
219
 
 
220
    # Second page illustrating effect of nrow, ncolumn for the same legend
 
221
    # data.
 
222
    pladv(0)
 
223
    plvpor(0.25, 0.75, 0.25, 0.75)
 
224
    plwind(0.0, 1.0, 0.0, 1.0)
 
225
    plbox("bc", 0.0, 0, "bc", 0.0, 0)
 
226
    plsfont(PL_FCI_SANS, -1, -1)
 
227
    plmtex("t", 8.0, 0.5, 0.5, "The effect of nrow, ncolumn, PL_LEGEND_ROW_MAJOR,")
 
228
    plmtex("t", 6.0, 0.5, 0.5, "and position for the same legend data")
 
229
 
 
230
    # Set up legend arrays with the correct size, type.
 
231
    nlegend = 7
 
232
    opt_array = zeros(nlegend, "int")
 
233
    text_colors = zeros(nlegend, "int")
 
234
    text = zeros(nlegend, "S200")
 
235
    box_colors = zeros(nlegend, "int")
 
236
    box_patterns = zeros(nlegend, "int")
 
237
    box_scales = zeros(nlegend)
 
238
    box_line_widths = zeros(nlegend, "int")
 
239
    line_colors = zeros(nlegend, "int")
 
240
    line_styles = zeros(nlegend, "int")
 
241
    line_widths = zeros(nlegend, "int")
 
242
    symbol_colors = zeros(nlegend, "int")
 
243
    symbol_scales = zeros(nlegend)
 
244
    symbol_numbers = zeros(nlegend, "int")
 
245
    symbols = zeros(nlegend, "S100")
 
246
 
 
247
    # Only specify legend data that are required according to the
 
248
    # value of opt_array for that entry.
 
249
    opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX
 
250
    for k in range(nlegend):
 
251
        opt_array[k] = PL_LEGEND_LINE | PL_LEGEND_SYMBOL
 
252
        line_styles[k] = 1
 
253
        line_widths[k] = 1
 
254
        symbol_scales[k] = 1.
 
255
        symbol_numbers[k] = 2
 
256
        symbols[k] = "*"
 
257
        text[k] = "%2.2d" % k
 
258
        text_colors[k] = 1 + (k % 8)
 
259
        line_colors[k] = 1 + (k % 8)
 
260
        symbol_colors[k] = 1 + (k % 8)
 
261
 
 
262
    # Use monotype fonts so that all legends are the same size.
 
263
    plsfont(PL_FCI_MONO, -1, -1)
 
264
    plscol0a( 15, 32, 32, 32, 0.70 )
 
265
 
 
266
    position = PL_POSITION_TOP | PL_POSITION_OUTSIDE
 
267
    opt = opt_base
 
268
    x = 0.
 
269
    y = 0.1
 
270
    nrow = 1
 
271
    ncolumn = nlegend
 
272
    (legend_width, legend_height) = \
 
273
     pllegend( opt, position, x, y,
 
274
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
275
              1., text_colors, text,
 
276
              box_colors, box_patterns, box_scales, box_line_widths,
 
277
              line_colors, line_styles, line_widths,
 
278
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
279
 
 
280
    position = PL_POSITION_BOTTOM | PL_POSITION_OUTSIDE
 
281
    opt = opt_base
 
282
    x = 0.
 
283
    y = 0.1
 
284
    nrow = 1
 
285
    ncolumn = nlegend
 
286
    (legend_width, legend_height) = \
 
287
    pllegend( opt, position, x, y,
 
288
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
289
              1., text_colors, text,
 
290
              box_colors, box_patterns, box_scales, box_line_widths,
 
291
              line_colors, line_styles, line_widths,
 
292
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
293
 
 
294
    position = PL_POSITION_LEFT | PL_POSITION_OUTSIDE
 
295
    opt = opt_base
 
296
    x = 0.1
 
297
    y = 0.
 
298
    nrow = nlegend
 
299
    ncolumn = 1
 
300
    (legend_width, legend_height) = \
 
301
    pllegend( opt, position, x, y,
 
302
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
303
              1., text_colors, text,
 
304
              box_colors, box_patterns, box_scales, box_line_widths,
 
305
              line_colors, line_styles, line_widths,
 
306
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
307
 
 
308
    position = PL_POSITION_RIGHT | PL_POSITION_OUTSIDE
 
309
    opt = opt_base
 
310
    x = 0.1
 
311
    y = 0.
 
312
    nrow = nlegend
 
313
    ncolumn = 1
 
314
    (legend_width, legend_height) = \
 
315
    pllegend( opt, position, x, y,
 
316
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
317
              1., text_colors, text,
 
318
              box_colors, box_patterns, box_scales, box_line_widths,
 
319
              line_colors, line_styles, line_widths,
 
320
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
321
 
 
322
    position = PL_POSITION_LEFT | PL_POSITION_TOP | PL_POSITION_INSIDE
 
323
    opt = opt_base
 
324
    x = 0.
 
325
    y = 0.
 
326
    nrow = 6
 
327
    ncolumn = 2
 
328
    (legend_width, legend_height) = \
 
329
    pllegend( opt, position, x, y,
 
330
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
331
              1., text_colors, text,
 
332
              box_colors, box_patterns, box_scales, box_line_widths,
 
333
              line_colors, line_styles, line_widths,
 
334
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
335
 
 
336
    position = PL_POSITION_RIGHT | PL_POSITION_TOP | PL_POSITION_INSIDE
 
337
    opt = opt_base | PL_LEGEND_ROW_MAJOR
 
338
    x = 0.
 
339
    y = 0.
 
340
    nrow = 6
 
341
    ncolumn = 2
 
342
    (legend_width, legend_height) = \
 
343
    pllegend( opt, position, x, y,
 
344
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
345
              1., text_colors, text,
 
346
              box_colors, box_patterns, box_scales, box_line_widths,
 
347
              line_colors, line_styles, line_widths,
 
348
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
349
 
 
350
    position = PL_POSITION_BOTTOM | PL_POSITION_INSIDE
 
351
    opt = opt_base | PL_LEGEND_ROW_MAJOR
 
352
    x = 0.
 
353
    y = 0.
 
354
    nrow = 3
 
355
    ncolumn = 3
 
356
    (legend_width, legend_height) = \
 
357
    pllegend( opt, position, x, y,
 
358
              0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0,
 
359
              1., text_colors, text,
 
360
              box_colors, box_patterns, box_scales, box_line_widths,
 
361
              line_colors, line_styles, line_widths,
 
362
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
363
 
 
364
    # Third page demonstrating legend alignment
 
365
    pladv(0)
 
366
    plvpor(0.0, 1.0, 0.0, 0.9)
 
367
    plwind(0.0, 1.0, 0.0, 1.0)
 
368
    plsfont(PL_FCI_SANS, -1, -1)
 
369
    plmtex("t", 2.0, 0.5, 0.5, "Demonstrate legend alignment")
 
370
 
 
371
    x = 0.1
 
372
    y = 0.1
 
373
    nturn = 4
 
374
    nlegend = 0
 
375
    position = PL_POSITION_TOP |  PL_POSITION_LEFT | PL_POSITION_SUBPAGE
 
376
    opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX
 
377
    opt = opt_base
 
378
    for i in range(9):
 
379
        # Set up legend arrays with the correct size, type.
 
380
        if i <= nturn:
 
381
            nlegend += 1
 
382
        else:
 
383
            nlegend -= 1
 
384
        nlegend = max(1, nlegend)
 
385
        opt_array = zeros(nlegend, "int")
 
386
        text_colors = zeros(nlegend, "int")
 
387
        text = zeros(nlegend, "S200")
 
388
        box_colors = zeros(nlegend, "int")
 
389
        box_patterns = zeros(nlegend, "int")
 
390
        box_scales = zeros(nlegend)
 
391
        box_line_widths = zeros(nlegend, "int")
 
392
        line_colors = zeros(nlegend, "int")
 
393
        line_styles = zeros(nlegend, "int")
 
394
        line_widths = zeros(nlegend, "int")
 
395
        symbol_colors = zeros(nlegend, "int")
 
396
        symbol_scales = zeros(nlegend)
 
397
        symbol_numbers = zeros(nlegend, "int")
 
398
        symbols = zeros(nlegend, "S100")
 
399
 
 
400
        # Only specify legend data that are required according to the
 
401
        # value of opt_array for that entry.
 
402
        for k in range(nlegend):
 
403
            opt_array[k] = PL_LEGEND_LINE | PL_LEGEND_SYMBOL
 
404
            line_styles[k] = 1
 
405
            line_widths[k] = 1
 
406
            symbol_scales[k] = 1.
 
407
            symbol_numbers[k] = 2
 
408
            symbols[k] = "*"
 
409
            text[k] = "%2.2d" % k
 
410
            text_colors[k] = 1 + (k % 8)
 
411
            line_colors[k] = 1 + (k % 8)
 
412
            symbol_colors[k] = 1 + (k % 8)
 
413
 
 
414
        # Use monotype fonts so that all legends are the same size.
 
415
        plsfont(PL_FCI_MONO, -1, -1)
 
416
        plscol0a( 15, 32, 32, 32, 0.70 )
 
417
 
 
418
        nrow = min(3, nlegend)
 
419
        ncolumn = 0
 
420
 
 
421
        (legend_width, legend_height) = \
 
422
        pllegend( opt, position, x, y,
 
423
                  0.025, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 1.5,
 
424
                  1., text_colors, text,
 
425
                  box_colors, box_patterns, box_scales, box_line_widths,
 
426
                  line_colors, line_styles, line_widths,
 
427
                  symbol_colors, symbol_scales, symbol_numbers, symbols )
 
428
        if i == nturn:
 
429
            position = PL_POSITION_TOP |  PL_POSITION_RIGHT | PL_POSITION_SUBPAGE
 
430
            opt = opt_base
 
431
            x = 1. - x
 
432
            y += legend_height
 
433
        else:
 
434
            x += legend_width
 
435
            y += legend_height
 
436
 
 
437
    # Fourth page illustrating various kinds of legends
 
438
    max_height = 0.
 
439
    xstart = 0.0
 
440
    ystart = 0.1
 
441
    x = xstart
 
442
    y = ystart
 
443
    text_scale = 0.90
 
444
    pladv(0)
 
445
    plvpor(0.0, 1., 0.0, 0.90)
 
446
    plwind(0.0, 1.0, 0.0, 1.0)
 
447
    # plbox("bc", 0.0, 0, "bc", 0.0, 0)
 
448
    plsfont(PL_FCI_SANS, -1, -1)
 
449
    plmtex("t", 2.0, 0.5, 0.5, "Demonstrate Various Kinds of Legends")
 
450
 
 
451
    # Set up legend arrays with the correct size, type.
 
452
    nlegend = 5
 
453
    opt_array = zeros(nlegend, "int")
 
454
    text_colors = zeros(nlegend, "int")
 
455
    text = zeros(nlegend, "S200")
 
456
    box_colors = zeros(nlegend, "int")
 
457
    box_patterns = zeros(nlegend, "int")
 
458
    box_scales = zeros(nlegend)
 
459
    box_line_widths = zeros(nlegend, "int")
 
460
    line_colors = zeros(nlegend, "int")
 
461
    line_styles = zeros(nlegend, "int")
 
462
    line_widths = zeros(nlegend, "int")
 
463
    symbol_colors = zeros(nlegend, "int")
 
464
    symbol_scales = zeros(nlegend)
 
465
    symbol_numbers = zeros(nlegend, "int")
 
466
    symbols = zeros(nlegend, "S100")
 
467
 
 
468
    # Only specify legend data that are required according to the
 
469
    # value of opt_array for that entry.
 
470
    position = PL_POSITION_LEFT | PL_POSITION_TOP
 
471
    opt_base = PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX | PL_LEGEND_TEXT_LEFT
 
472
 
 
473
    # Set up None, Box, Line, Symbol, and Line & Symbol legend entries.
 
474
    opt_array[0] = PL_LEGEND_NONE
 
475
    text[0] = "None"
 
476
    text_colors[0] = 1
 
477
 
 
478
    opt_array[1] = PL_LEGEND_COLOR_BOX
 
479
    text[1] = "Box"
 
480
    text_colors[1] = 2
 
481
    box_colors[1] = 2
 
482
    box_patterns[1] = 0
 
483
    box_scales[1] = 0.8
 
484
    box_line_widths[1] = 1
 
485
 
 
486
    opt_array[2] = PL_LEGEND_LINE
 
487
    text[2] = "Line"
 
488
    text_colors[2] = 3
 
489
    line_colors[2] = 3
 
490
    line_styles[2] = 1
 
491
    line_widths[2] = 1
 
492
 
 
493
    opt_array[3] = PL_LEGEND_SYMBOL
 
494
    text[3] = "Symbol"
 
495
    text_colors[3] = 4
 
496
    symbol_colors[3] = 4
 
497
    symbol_scales[3] = text_scale
 
498
    symbol_numbers[3] = 4
 
499
    symbols[3] = special_symbols[2]
 
500
 
 
501
    opt_array[4] = PL_LEGEND_SYMBOL | PL_LEGEND_LINE
 
502
    text[4] = "L & S"
 
503
    text_colors[4] = 5
 
504
    line_colors[4] = 5
 
505
    line_styles[4] = 1
 
506
    line_widths[4] = 1
 
507
    symbol_colors[4] = 5
 
508
    symbol_scales[4] = text_scale
 
509
    symbol_numbers[4] = 4
 
510
    symbols[4] = special_symbols[2]
 
511
 
 
512
    opt = opt_base
 
513
    plscol0a( 15, 32, 32, 32, 0.70 )
 
514
    (legend_width, legend_height) = \
 
515
    pllegend( opt, position, x, y,
 
516
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
517
              0., text_colors, text,
 
518
              box_colors, box_patterns, box_scales, box_line_widths,
 
519
              line_colors, line_styles, line_widths,
 
520
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
521
    max_height = max(max_height, legend_height)
 
522
 
 
523
    # Set up symbol legend entries with various symbols.
 
524
    for i in range(nlegend):
 
525
        opt_array[i] = PL_LEGEND_SYMBOL
 
526
        text[i] = "Symbol " + special_symbols[i]
 
527
        text_colors[i] = i+1
 
528
        symbol_colors[i] = i+1
 
529
        symbol_scales[i] = text_scale
 
530
        symbol_numbers[i] = 4
 
531
        symbols[i] = special_symbols[i]
 
532
 
 
533
    opt = opt_base
 
534
    x += legend_width
 
535
    plscol0a( 15, 32, 32, 32, 0.70 )
 
536
    (legend_width, legend_height) = \
 
537
    pllegend( opt, position, x, y,
 
538
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
539
              0., text_colors, text,
 
540
              box_colors, box_patterns, box_scales, box_line_widths,
 
541
              line_colors, line_styles, line_widths,
 
542
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
543
    max_height = max(max_height, legend_height)
 
544
 
 
545
    # Set up symbol legend entries with various numbers of symbols.
 
546
    for i in range(nlegend):
 
547
        opt_array[i] = PL_LEGEND_SYMBOL
 
548
        text[i] = "Symbol Number %d" % (i+2)
 
549
        text_colors[i] = i+1
 
550
        symbol_colors[i] = i+1
 
551
        symbol_scales[i] = text_scale
 
552
        symbol_numbers[i] = i+2
 
553
        symbols[i] = special_symbols[2]
 
554
 
 
555
    opt = opt_base
 
556
    x += legend_width
 
557
    plscol0a( 15, 32, 32, 32, 0.70 )
 
558
    (legend_width, legend_height) = \
 
559
    pllegend( opt, position, x, y,
 
560
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
561
              0., text_colors, text,
 
562
              box_colors, box_patterns, box_scales, box_line_widths,
 
563
              line_colors, line_styles, line_widths,
 
564
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
565
    max_height = max(max_height, legend_height)
 
566
 
 
567
    # Set up box legend entries with various colours.
 
568
    for i in range(nlegend):
 
569
        opt_array[i] = PL_LEGEND_COLOR_BOX
 
570
        text[i] = "%s %d" % ("Box Color",i+1)
 
571
        text_colors[i] = i+1
 
572
        box_colors[i] = i+1
 
573
        box_patterns[i] = 0
 
574
        box_scales[i] = 0.8
 
575
        box_line_widths[i] = 1
 
576
 
 
577
    opt = opt_base
 
578
    # Use new origin
 
579
    x = xstart
 
580
    y += max_height
 
581
    max_height = 0.
 
582
    plscol0a( 15, 32, 32, 32, 0.70 )
 
583
    (legend_width, legend_height) = \
 
584
    pllegend( opt, position, x, y,
 
585
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
586
              0., text_colors, text,
 
587
              box_colors, box_patterns, box_scales, box_line_widths,
 
588
              line_colors, line_styles, line_widths,
 
589
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
590
    max_height = max(max_height, legend_height)
 
591
 
 
592
    # Set up box legend entries with various patterns.
 
593
    for i in range(nlegend):
 
594
        opt_array[i] = PL_LEGEND_COLOR_BOX
 
595
        text[i] = "%s %d" % ("Box Pattern",i)
 
596
        text_colors[i] = 2
 
597
        box_colors[i] = 2
 
598
        box_patterns[i] = i
 
599
        box_scales[i] = 0.8
 
600
        box_line_widths[i] = 1
 
601
 
 
602
    opt = opt_base
 
603
    x += legend_width
 
604
    plscol0a( 15, 32, 32, 32, 0.70 )
 
605
    (legend_width, legend_height) = \
 
606
    pllegend( opt, position, x, y,
 
607
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
608
              0., text_colors, text,
 
609
              box_colors, box_patterns, box_scales, box_line_widths,
 
610
              line_colors, line_styles, line_widths,
 
611
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
612
    max_height = max(max_height, legend_height)
 
613
 
 
614
    # Set up box legend entries with various box pattern line widths.
 
615
    for i in range(nlegend):
 
616
        opt_array[i] = PL_LEGEND_COLOR_BOX
 
617
        text[i] = "%s %d" % ("Box Line Width",i+1)
 
618
        text_colors[i] = 2
 
619
        box_colors[i] = 2
 
620
        box_patterns[i] = 3
 
621
        box_scales[i] = 0.8
 
622
        box_line_widths[i] = i+1
 
623
 
 
624
    opt = opt_base
 
625
    x += legend_width
 
626
    plscol0a( 15, 32, 32, 32, 0.70 )
 
627
    (legend_width, legend_height) = \
 
628
    pllegend( opt, position, x, y,
 
629
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
630
              0., text_colors, text,
 
631
              box_colors, box_patterns, box_scales, box_line_widths,
 
632
              line_colors, line_styles, line_widths,
 
633
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
634
    max_height = max(max_height, legend_height)
 
635
 
 
636
    # Set up line legend entries with various colours.
 
637
    for i in range(nlegend):
 
638
        opt_array[i] = PL_LEGEND_LINE
 
639
        text[i] = "%s %d" % ("Line Color",i+1)
 
640
        text_colors[i] = i+1
 
641
        line_colors[i] = i+1
 
642
        line_styles[i] = 1
 
643
        line_widths[i] = 1
 
644
 
 
645
    opt = opt_base
 
646
    # Use new origin
 
647
    x = xstart
 
648
    y += max_height
 
649
    max_height = 0.
 
650
    plscol0a( 15, 32, 32, 32, 0.70 )
 
651
    (legend_width, legend_height) = \
 
652
    pllegend( opt, position, x, y,
 
653
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
654
              0., text_colors, text,
 
655
              box_colors, box_patterns, box_scales, box_line_widths,
 
656
              line_colors, line_styles, line_widths,
 
657
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
658
    max_height = max(max_height, legend_height)
 
659
 
 
660
    # Set up line legend entries with various styles
 
661
    for i in range(nlegend):
 
662
        opt_array[i] = PL_LEGEND_LINE
 
663
        text[i] = "%s %d" % ("Line Style",i+1)
 
664
        text_colors[i] = 2
 
665
        line_colors[i] = 2
 
666
        line_styles[i] = i+1
 
667
        line_widths[i] = 1
 
668
 
 
669
    opt = opt_base
 
670
    x += legend_width
 
671
    plscol0a( 15, 32, 32, 32, 0.70 )
 
672
    (legend_width, legend_height) = \
 
673
    pllegend( opt, position, x, y,
 
674
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
675
              0., text_colors, text,
 
676
              box_colors, box_patterns, box_scales, box_line_widths,
 
677
              line_colors, line_styles, line_widths,
 
678
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
679
    max_height = max(max_height, legend_height)
 
680
 
 
681
    # Set up line legend entries with various widths.
 
682
    for i in range(nlegend):
 
683
        opt_array[i] = PL_LEGEND_LINE
 
684
        text[i] = "%s %d" % ("Line Width",i+1)
 
685
        text_colors[i] = 2
 
686
        line_colors[i] = 2
 
687
        line_styles[i] = 1
 
688
        line_widths[i] = i+1
 
689
 
 
690
    opt = opt_base
 
691
    x += legend_width
 
692
    plscol0a( 15, 32, 32, 32, 0.70 )
 
693
    (legend_width, legend_height) = \
 
694
    pllegend( opt, position, x, y,
 
695
              0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0,
 
696
              0., text_colors, text,
 
697
              box_colors, box_patterns, box_scales, box_line_widths,
 
698
              line_colors, line_styles, line_widths,
 
699
              symbol_colors, symbol_scales, symbol_numbers, symbols )
 
700
    max_height = max(max_height, legend_height)
 
701
 
 
702
    if False:
 
703
        # Color bar examples
 
704
        values_small = [ 0.0, 1.0 ]
 
705
        values_uneven = [ 0.0, 2.0, 2.6, 3.4, 6.0, 7.0, 8.0, 9.0, 10.0 ]
 
706
        values_even = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]
 
707
        plcolorbar_example_1( PL_COLORBAR_IMAGE, 0.0, 0, values_small, "Image Color Bars" )
 
708
        plcolorbar_example_2( PL_COLORBAR_IMAGE, 0.0, 0, values_small, "Image Color Bars" )
 
709
        plcolorbar_example_1( PL_COLORBAR_SHADE | PL_COLORBAR_SHADE_LABEL, 0.0, 0, values_uneven, "Shade Color Bars - Uneven Steps" )
 
710
        plcolorbar_example_2( PL_COLORBAR_SHADE, 3.0, 3, values_even, "Shade Color Bars - Even Steps" )
 
711
        plcolorbar_example_1( PL_COLORBAR_GRADIENT, 0.5, 5, values_small, "Gradient Color Bars" )
 
712
        plcolorbar_example_2( PL_COLORBAR_GRADIENT, 0.5, 5, values_small, "Gradient Color Bars" )
 
713
main()