~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/python/xw30.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
# $Id: xw30.py 11680 2011-03-27 17:57:51Z airwin $
 
2
 
 
3
#  Copyright (C) 2008 Hazen Babcock
 
4
#  Copyright (C) 2008 Andrew Ross
 
5
 
 
6
#  Alpha color values demonstration.
 
7
#
 
8
#  This file is part of PLplot.
 
9
#
 
10
#  PLplot is free software; you can redistribute it and/or modify
 
11
#  it under the terms of the GNU Library General Public License as published
 
12
#  by the Free Software Foundation; either version 2 of the License, or
 
13
#  (at your option) any later version.
 
14
#
 
15
#  PLplot is distributed in the hope that it will be useful,
 
16
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#  GNU Library General Public License for more details.
 
19
#
 
20
#  You should have received a copy of the GNU Library General Public License
 
21
#  along with PLplot; if not, write to the Free Software
 
22
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
23
#
 
24
from plplot_py_demos import *
 
25
 
 
26
red   = array([  0, 255,   0,   0])
 
27
green = array([  0,   0, 255,   0])
 
28
blue  = array([  0,   0,   0, 255])
 
29
alpha = array([1.0, 1.0, 1.0, 1.0])
 
30
 
 
31
pos = array([0.0, 1.0])
 
32
rcoord = array([1.0, 1.0])
 
33
gcoord = array([0.0, 0.0])
 
34
bcoord = array([0.0, 0.0])
 
35
acoord = array([0.0, 1.0])
 
36
rev = array([0, 0])
 
37
 
 
38
def main():
 
39
 
 
40
  px = array([0.1, 0.5, 0.5, 0.1])
 
41
  py = array([0.1, 0.1, 0.5, 0.5])
 
42
 
 
43
 
 
44
  plscmap0n (4)
 
45
  plscmap0a (red, green, blue, alpha)
 
46
 
 
47
  # 
 
48
  #   Page 1:
 
49
  #
 
50
  #   This is a series of red, green and blue rectangles overlaid
 
51
  #   on each other with gradually increasing transparency.
 
52
  
 
53
 
 
54
  # Set up the window 
 
55
  pladv (0)
 
56
  plvpor (0.0, 1.0, 0.0, 1.0)
 
57
  plwind (0.0, 1.0, 0.0, 1.0)
 
58
  plcol0 (0)
 
59
  plbox ("", 1.0, 0, "", 1.0, 0)
 
60
 
 
61
  # Draw the boxes
 
62
  for i in range(9):
 
63
    icol = i%3 + 1
 
64
 
 
65
    # Get a color, change its transparency and 
 
66
    # set it as the current color. 
 
67
    rgba = plgcol0a (icol)
 
68
    plscol0a (icol, rgba[0], rgba[1], rgba[2], 1.0 - float(i)/9.0)
 
69
    plcol0 (icol)
 
70
 
 
71
    # Draw the rectangle 
 
72
    plfill (px, py)
 
73
 
 
74
    # Shift the rectangles coordinates
 
75
    px += 0.5/9.0
 
76
    py += 0.5/9.0
 
77
 
 
78
  # 
 
79
  #   Page 2:
 
80
  #
 
81
  #   This is a bunch of boxes colored red, green or blue with a single 
 
82
  #   large (red) box of linearly varying transparency overlaid. The
 
83
  #   overlaid box is completely transparent at the bottom and completely
 
84
  #   opaque at the top.
 
85
  
 
86
 
 
87
  # Set up the window 
 
88
  pladv(0)
 
89
  plvpor(0.1, 0.9, 0.1, 0.9)
 
90
  plwind(0.0, 1.0, 0.0, 1.0)
 
91
 
 
92
  # Draw the boxes. There are 25 of them drawn on a 5 x 5 grid. 
 
93
  for i in range(5): 
 
94
    # Set box X position 
 
95
    px[0] = 0.05 + 0.2 * i
 
96
    px[1] = px[0] + 0.1
 
97
    px[2] = px[1]
 
98
    px[3] = px[0]
 
99
 
 
100
    # We don't want the boxes to be transparent, so since we changed   
 
101
    # the colors transparencies in the first example we have to change 
 
102
    # the transparencies back to completely opaque. 
 
103
    icol = i%3 + 1
 
104
    rgba = plgcol0a (icol)
 
105
    plscol0a (icol, rgba[0], rgba[1], rgba[2], 1.0)
 
106
    plcol0 (icol)
 
107
    for j in range(5):
 
108
      # Set box y position and draw the box. 
 
109
      py[0] = 0.05 + 0.2 * j
 
110
      py[1] = py[0]
 
111
      py[2] = py[0] + 0.1
 
112
      py[3] = py[2]
 
113
      plfill(px, py)
 
114
 
 
115
  # Create the color map with 128 colors and use plscmap1la to initialize 
 
116
  # the color values with a linearly varying red transparency (or alpha) 
 
117
  plscmap1n(128)
 
118
  plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev)
 
119
 
 
120
  # Use that cmap1 to create a transparent red gradient for the whole
 
121
  # window.
 
122
  px[0] = 0.
 
123
  px[1] = 1.
 
124
  px[2] = 1.
 
125
  px[3] = 0.
 
126
   
 
127
  py[0] = 0.
 
128
  py[1] = 0.
 
129
  py[2] = 1.
 
130
  py[3] = 1.
 
131
 
 
132
  plgradient(px, py, 90.)
 
133
 
 
134
main()