1#  Copyright (C) 2001-2016 Alan W. Irwin
2
3#  Simple line plot and multiple windows demo.
4#
5#  This file is part of PLplot.
6#
7#  PLplot is free software; you can redistribute it and/or modify
8#  it under the terms of the GNU Library General Public License as published
9#  by the Free Software Foundation; either version 2 of the License, or
10#  (at your option) any later version.
11#
12#  PLplot is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU Library General Public License for more details.
16#
17#  You should have received a copy of the GNU Library General Public License
18#  along with PLplot; if not, write to the Free Software
19#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20#
21
22from numpy import *
23
24# main
25#
26# Generates several simple line plots.  Demonstrates:
27#   - subwindow capability
28#   - setting up the window, drawing plot, and labelling
29#   - changing the color
30#   - automatic axis rescaling to exponential notation
31#   - placing the axes in the middle of the box
32#   - gridded coordinate axes
33
34def main(w):
35
36    # For starting from scratch this call to pladv increments cursub, but
37    # then the following plssub sets it to zero so the whole thing is
38    # essentially a nop.  However, for the case when other examples are run
39    # first, this call to pladv is absolutely essential to finish the
40    # preceding page.
41    w.pladv(0)
42    # Do plots on 4 subwindows of the first page
43    w.plssub(2, 2)
44
45    # Do a plot with one range of data
46
47    plot1(w, 6., 1., 0., 0.)
48
49    # Do a plot with another range of data
50
51    digmax = 5
52    w.plsyax(digmax, 0)
53    plot1(w, 1., 0.0014, 0., 0.0185)
54
55    plot2(w)
56
57    plot3(w)
58
59    # Restore defaults
60    w.plssub(1, 1)
61    w.pleop()
62    # Must be done independently because otherwise this changes output files
63    # and destroys agreement with C examples.
64    #w.plcol0(1)
65
66# ===============================================================
67
68def plot1(w, xscale, yscale, xoff, yoff):
69
70    x = xoff + (xscale/60.)*(1+arange(60))
71    y = yoff + yscale*pow(x,2.)
72
73    xmin = x[0]
74    xmax = x[59]
75    ymin = y[0]
76    ymax = y[59]
77
78    xs = x[3::10]
79    ys = y[3::10]
80
81    # Set up the viewport and window using pl.env. The range in X
82    # is 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes
83    # are scaled separately (just = 0), and we just draw a
84    # labelled box (axis = 0).
85
86    w.plcol0(1)
87    w.plenv(xmin, xmax, ymin, ymax, 0, 0)
88    w.plcol0(2)
89    w.pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2")
90
91    # Plot the data points
92
93    w.plcol0(4)
94    w.plpoin(xs, ys, 9)
95
96    # Draw the line through the data
97
98    w.plcol0(3)
99    w.plline(x, y)
100
101# ===============================================================
102
103def plot2(w):
104
105    # Set up the viewport and window using pl.env. The range in X
106    # is -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes
107    # are scaled separately (just = 0), and we draw a box with
108    # axes (axis = 1).
109
110    w.plcol0(1)
111    w.plenv(-2.0, 10.0, -0.4, 1.2, 0, 1)
112    w.plcol0(2)
113    w.pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function")
114
115    # Fill up the arrays
116
117    x = (arange(100)-19)/6.0
118    if 0.0 in x:
119        #replace 0.0 by small value that gives the same sinc(x) result.
120        x[list(x).index(0.0)] = 1.e-30
121    y = sin(x)/x
122
123    # Draw the line
124
125    w.plcol0(3)
126    w.plwidth(2)
127    w.plline(x, y)
128    w.plwidth(1)
129
130# ===============================================================
131
132def plot3(w):
133
134    # For the final graph we wish to override the default tick
135    # intervals, so do not use pl.env
136
137    w.pladv(0)
138
139    # Use standard viewport, and define X range from 0 to 360
140    # degrees, Y range from -1.2 to 1.2.
141
142    w.plvsta()
143    w.plwind(0.0, 360.0, -1.2, 1.2)
144
145    # Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
146
147    w.plcol0(1)
148    w.plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2)
149
150    # Superimpose a dashed line grid, with 1.5 mm marks and spaces.
151
152    w.plstyl([1500], [1500])
153    w.plcol0(2)
154    w.plbox("g", 30.0, 0, "g", 0.2, 0)
155    w.plstyl([], [])
156
157    w.plcol0(3)
158    w.pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function")
159
160    x = 3.6*arange(101)
161    y = sin((pi/180.)*x)
162
163    w.plcol0(4)
164    w.plline(x, y)
165