source: branches/plotter2/python/plotter2.py@ 3137

Last change on this file since 3137 was 2827, checked in by WataruKawasaki, 11 years ago

New Development: No

JIRA Issue: Yes CAS-3620

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: modified plotter2.save() so that the previous filename and device are restored finally.


File size: 11.0 KB
Line 
1from os.path import expanduser, expandvars
2from asap._asap import Plotter2
3
4class plotter2:
5 def __init__(self):
6 self._plotter = Plotter2()
7
8 def set_output(self, filename=None, dev=None):
9 if filename is None:
10 filename = ''
11 dev = 'xwindow'
12 else:
13 filename = filename.strip()
14 if filename == '':
15 dev = 'xwindow'
16 else:
17 if (dev is None) or (dev.strip() == ''):
18 fnamelem = filename.lower().split('.')
19 dev = fnamelem[len(fnamelem)-1].strip()
20 if dev == 'ps': dev = 'cps'
21
22 self._plotter.set_filename(expanduser(expandvars(filename)))
23 self._plotter.set_device(dev.strip())
24
25 def set_vp(self, xmin, xmax, ymin, ymax, id=None):
26 if id is None:
27 if self._plotter.get_hasdefaultvp():
28 self._plotter.set_viewport(xmin, xmax, ymin, ymax, 0)
29 else:
30 return self._plotter.add_viewport(xmin, xmax, ymin, ymax)
31 else:
32 self._plotter.set_viewport(xmin, xmax, ymin, ymax, id)
33
34 def show_vp(self, vpid=None):
35 if vpid is None: vpid = -1
36 self._plotter.show_viewport(vpid)
37
38 def hide_vp(self, vpid=None):
39 if vpid is None: vpid = -1
40 self._plotter.hide_viewport(vpid)
41
42 def set_range(self, xmin, xmax, ymin, ymax, vpid=None):
43 if vpid is None: vpid = -1
44 self._plotter.set_range(xmin, xmax, ymin, ymax, vpid)
45
46 def set_xrange(self, xmin, xmax, vpid=None):
47 if vpid is None: vpid = -1
48 self._plotter.set_range_x(xmin, xmax, vpid)
49
50 def set_yrange(self, ymin, ymax, vpid=None):
51 if vpid is None: vpid = -1
52 self._plotter.set_range_y(ymin, ymax, vpid)
53
54 def get_xrange(self, vpid=None):
55 if vpid is None: vpid = -1
56 return self._plotter.get_range_x(vpid)
57
58 def get_yrange(self, vpid=None):
59 if vpid is None: vpid = -1
60 return self._plotter.get_range_y(vpid)
61
62 def set_autorange(self, vpid=None):
63 if vpid is None: vpid = -1
64 self._plotter.set_autorange(vpid)
65
66 def set_xautorange(self, vpid=None):
67 if vpid is None: vpid = -1
68 self._plotter.set_autorange_x(vpid)
69
70 def set_yautorange(self, vpid=None):
71 if vpid is None: vpid = -1
72 self._plotter.set_autorange_y(vpid)
73
74 def set_fontsize(self, size, vpid=None):
75 if vpid is None: vpid = -1
76 self._plotter.set_fontsize(size, vpid)
77
78 def set_xtics(self, interval_major, num_minor=None, vpid=None):
79 if vpid is None: vpid = -1
80 if num_minor is None: num_minor = 5
81 self._plotter.set_tics_x(interval_major, num_minor, vpid)
82
83 def set_ytics(self, interval_major, num_minor=None, vpid=None):
84 if vpid is None: vpid = -1
85 if num_minor is None: num_minor = 5
86 self._plotter.set_tics_y(interval_major, num_minor, vpid)
87
88 def set_xautotics(self, vpid=None):
89 if vpid is None: vpid = -1
90 self._plotter.set_autotics_x(vpid)
91
92 def set_yautotics(self, vpid=None):
93 if vpid is None: vpid = -1
94 self._plotter.set_autotics_y(vpid)
95
96 def set_xnuminterval(self, interval, vpid=None):
97 if vpid is None: vpid = -1
98 self._plotter.set_ninterval_x(interval, vpid)
99
100 def set_ynuminterval(self, interval, vpid=None):
101 if vpid is None: vpid = -1
102 self._plotter.set_ninterval_y(interval, vpid)
103
104 def set_xnumlocation(self, location=None, vpid=None):
105 if vpid is None: vpid = -1
106 if location is None: location = "l"
107 self._plotter.set_nlocation_x(location.lower(), vpid)
108
109 def set_ynumlocation(self, location=None, vpid=None):
110 if vpid is None: vpid = -1
111 if location is None: location = "b"
112 self._plotter.set_nlocation_y(location.lower(), vpid)
113
114 def set_data(self, xdata, ydata, vpid=None, dataid=None):
115 if dataid is None:
116 if vpid is None: vpid = -1
117 dataid = -1
118
119 self._plotter.set_data(xdata, ydata, vpid, dataid)
120
121 def set_line(self, color, width=None, style=None, vpid=None, dataid=None):
122 if width is None: width = 1
123 if style is None: style = "solid"
124 if vpid is None: vpid = -1
125 if dataid is None: dataid = -1
126
127 coloridx = self.get_colorindex(color)
128 styleidx = self.get_linestyleindex(style)
129 self._plotter.set_line(coloridx, width, styleidx, vpid, dataid)
130
131 def show_line(self, vpid=None, dataid=None):
132 if dataid is None:
133 if vpid is None: vpid = -1
134 dataid = -1
135
136 self._plotter.show_line(vpid, dataid)
137
138 def hide_line(self, vpid=None, dataid=None):
139 if dataid is None:
140 if vpid is None: vpid = -1
141 dataid = -1
142
143 self._plotter.hide_line(vpid, dataid)
144
145 def set_point(self, type, size, color, vpid=None, dataid=None):
146 if dataid is None:
147 if vpid is None: vpid = -1
148 dataid = -1
149 coloridx = self.get_colorindex(color)
150 self._plotter.set_point(type, size, coloridx, vpid, dataid)
151
152 def show_point(self, vpid=None, dataid=None):
153 if dataid is None:
154 if vpid is None: vpid = -1
155 dataid = -1
156
157 self._plotter.show_point(vpid, dataid)
158
159 def hide_point(self, vpid=None, dataid=None):
160 if dataid is None:
161 if vpid is None: vpid = -1
162 dataid = -1
163
164 self._plotter.hide_point(vpid, dataid)
165
166 def set_xmask(self, xmin, xmax, color=None, fstyle=None, width=None, hsep=None, vpid=None):
167 if color is None: color = "lightgray"
168 if fstyle is None: fstyle = "solid"
169 if width is None: width = 1
170 if hsep is None: hsep = 1.0
171 if vpid is None: vpid = -1
172 coloridx = self.get_colorindex(color)
173 fstyleidx = self.get_fillstyleindex(fstyle)
174 self._plotter.set_mask_x(xmin, xmax, coloridx, fstyleidx, width, hsep, vpid)
175
176 def set_xlabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
177 if style is None: style = ""
178 if size is None: size = 1.1
179 if posx is None: posx = -1.0
180 if posy is None: posy = -1.0
181 if vpid is None: vpid = -1
182
183 self._plotter.set_label_x(label, posx, posy, size, style, 1, 0, vpid)
184
185 def set_ylabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
186 if style is None: style = ""
187 if size is None: size = 1.1
188 if posx is None: posx = -1.0
189 if posy is None: posy = -1.0
190 if vpid is None: vpid = -1
191
192 self._plotter.set_label_y(label, posx, posy, size, style, 1, 0, vpid)
193
194 def set_title(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
195 if style is None: style = ""
196 if size is None: size = 1.5
197 if posx is None: posx = -1.0
198 if posy is None: posy = -1.0
199 if vpid is None: vpid = -1
200
201 self._plotter.set_title(label, posx, posy, size, style, 1, 0, vpid)
202
203 def set_vpbgcolor(self, bgcolor, vpid=None):
204 if vpid is None: vpid = -1
205
206 if bgcolor.strip() == "":
207 coloridx = -1
208 else:
209 coloridx = self.get_colorindex(bgcolor)
210
211 self._plotter.set_vpbgcolor(coloridx, vpid)
212
213 def plot(self):
214 self._plotter.plot()
215
216 def save(self, filename):
217 prev_filename = self._plotter.get_filename()
218 prev_dev = self._plotter.get_device()
219
220 self.set_output(filename)
221 self.plot()
222
223 self.set_output(prev_filename, prev_dev)
224
225 def get_vinfo(self):
226 self._plotter.get_vinfo()
227
228 def get_colorindex(self, colorname):
229 name = colorname.strip().lower()
230
231 if name == "white": idx = 0 # our definition of bgcolor
232 if name == "black": idx = 1 # our definition of fgcolor
233 if name == "red": idx = 2
234 if name == "green": idx = 3
235 if name == "blue": idx = 4
236 if name == "cyan": idx = 5
237 if name == "magenta": idx = 6
238 if name == "yellow": idx = 7
239 if name == "orange": idx = 8
240 if name == "yellowgreen": idx = 9
241 if name == "emerald": idx = 10
242 if name == "skyblue": idx = 11
243 if name == "purple": idx = 12
244 if name == "pink": idx = 13
245 if name == "gray": idx = 14
246 if name == "lightgray": idx = 15
247
248 return idx
249
250 def list_colornames(self):
251 print "plotter2: default color list ----"
252 print " (0) white (background)"
253 print " (1) black (foreground)"
254 print " (2) red"
255 print " (3) green"
256 print " (4) blue"
257 print " (5) cyan"
258 print " (6) magenta"
259 print " (7) yellow"
260 print " (8) orange"
261 print " (9) yellowgreen"
262 print " (10) emerald"
263 print " (11) skyblue"
264 print " (12) purple"
265 print " (13) pink"
266 print " (14) gray"
267 print " (15) lightgray"
268 print "---------------------------------"
269
270 def get_linestyleindex(self, fstyle):
271 style = fstyle.strip().lower()
272 if style == "solid": idx = 1
273 if style == "outline": idx = 2
274 if style == "hatched": idx = 3
275 if style == "crosshatched": idx = 4
276
277 return idx
278
279 def list_linestyles(self):
280 print "plotter2: fill style list ----"
281 print " (1) solid"
282 print " (2) dashed"
283 print " (3) dash-dotted"
284 print " (4) dotted"
285 print " (5) dash-dot-dot-dotted"
286 print "------------------------------"
287
288 def get_fillstyleindex(self, fstyle):
289 style = fstyle.strip().lower()
290 if style == "solid": idx = 1
291 if style == "outline": idx = 2
292 if style == "hatched": idx = 3
293 if style == "crosshatched": idx = 4
294
295 return idx
296
297 def list_fillstyles(self):
298 print "plotter2: fill style list ----"
299 print " (1) solid"
300 print " (2) outline"
301 print " (3) hatched"
302 print " (4) crosshatched"
303 print "------------------------------"
304
305"""
306 def set_annotation(self, label, posx=None, posy=None, angle=None, fjust=None, size=None, style=None, color=None, bgcolor=None, vpid=None):
307 if posx is None: posx = -1.0
308 if posy is None: posy = -1.0
309 if angle is None: angle = 0.0
310 if fjust is None: fjust = 0.5
311 if size is None: size = 2.0
312 if style is None: style = ""
313 if color is None: color = 1 #default foreground colour (b)
314 if bgcolor is None: bgcolor = 0 #default backgound colour (w)
315 if vpid is None: vpid = -1
316
317 coloridx = self.get_colorindex(color)
318 bgcoloridx = self.get_colorindex(bgcolor)
319 self._plotter.set_annotation(label, posx, posy, angle, fjust, size, style, coloridx, bgcoloridx, vpid)
320"""
Note: See TracBrowser for help on using the repository browser.