Debian Codegraph @

07p/python/auto/graphics/plotter.py

raw symbols SCIP
1 #! /usr/bin/env python
2 try:
3 from auto.graphics import grapher_mpl as grapher
4 except ImportError:
5 from auto.graphics import grapher
6 print("Using plain TkInter for plotting. You can obtain better quality graphics")
7 print("using matplotlib (http://matplotlib.sf.net).")
8 from auto import parseB
9 from auto import parseS
10 from auto import parseC
11 from auto import AUTOutil
12 import os
13 import gc
14 import sys
15 Axes3D = grapher.Axes3D
16
17 class plotter(grapher.GUIGrapher):
18 def __init__(self,parent=None,**kw):
19
20 optionDefaults = {}
21 # The kind of diagram (single solution vs. bifur diagram)
22 optionDefaults["type"] = ("bifurcation",self.__optionCallback)
23 # The X column
24 optionDefaults["bifurcation_x"] = ([0],self.__optionCallback)
25 optionDefaults["solution_x"] = ([-1],self.__optionCallback)
26 # The Y column
27 optionDefaults["bifurcation_y"] = ([1],self.__optionCallback)
28 optionDefaults["solution_y"] = ([0],self.__optionCallback)
29 # The Z column
30 optionDefaults["bifurcation_z"] = (None,self.__optionCallback)
31 optionDefaults["solution_z"] = (None,self.__optionCallback)
32 # The coordinate names
33 optionDefaults["bifurcation_coordnames"] = (None,self.__optionCallback)
34 optionDefaults["solution_indepvarname"] = (None,self.__optionCallback)
35 optionDefaults["solution_coordnames"] = (None,self.__optionCallback)
36 optionDefaults["labelnames"] = (None,self.__optionCallback)
37 # Sets of labels that the user is likely to want to use
38 optionDefaults["label_defaults"] = (None,self.__optionCallback)
39 # Sets of columns that the user is likely to want to use
40 optionDefaults["bifurcation_column_defaults"] = (None,self.__optionCallback)
41 optionDefaults["solution_column_defaults"] = (None,self.__optionCallback)
42 # The index of the solution we wish to draw
43 optionDefaults["index"] = ([0],self.__optionCallback)
44 # The label of the solution we wish to draw
45 optionDefaults["label"] = ([0],self.__optionCallback)
46
47 # Already parsed data structures
48 optionDefaults["bifurcation_diagram"] = (parseB.parseB(),self.__optionCallback)
49 optionDefaults["solution"] = (parseS.parseS(),self.__optionCallback)
50 optionDefaults["bifurcation_diagram_filename"] = ("",self.__optionCallback)
51 optionDefaults["solution_filename"] = ("",self.__optionCallback)
52 optionDefaults["runner"] = (None,self.__optionCallback)
53 optionDefaults["mark_t"] = (None,self.__optionCallback)
54
55 optionDefaults["letter_symbols"] = (True,self.__optionCallback)
56 optionDefaults["bifurcation_symbol"] = ("B",self.__optionCallback)
57 optionDefaults["limit_point_symbol"] = ("L",self.__optionCallback)
58 optionDefaults["hopf_symbol"] = ("H",self.__optionCallback)
59 optionDefaults["zero_hopf_symbol"] = ("ZH",self.__optionCallback)
60 optionDefaults["bogdanov_takens_symbol"] = ("BT",self.__optionCallback)
61 optionDefaults["cusp_symbol"] = ("CP",self.__optionCallback)
62 optionDefaults["generalized_hopf_symbol"]= ("GH",self.__optionCallback)
63 optionDefaults["1_1_resonance_symbol"] = ("R1",self.__optionCallback)
64 optionDefaults["1_2_resonance_symbol"] = ("R2",self.__optionCallback)
65 optionDefaults["1_3_resonance_symbol"] = ("R3",self.__optionCallback)
66 optionDefaults["1_4_resonance_symbol"] = ("R4",self.__optionCallback)
67 optionDefaults["fold_flip_symbol"] = ("LPD",self.__optionCallback)
68 optionDefaults["fold_torus_symbol"] = ("LTR",self.__optionCallback)
69 optionDefaults["flip_torus_symbol"] = ("PTR",self.__optionCallback)
70 optionDefaults["torus_torus_symbol"] = ("TTR",self.__optionCallback)
71 optionDefaults["period_doubling_symbol"] = ("D",self.__optionCallback)
72 optionDefaults["torus_symbol"] = ("T",self.__optionCallback)
73 optionDefaults["user_point_symbol"] = ("U",self.__optionCallback)
74 optionDefaults["error_symbol"] = ("X",self.__optionCallback)
75
76 optionDefaults["ps_colormode"] = ("color",self.__optionCallback)
77 optionDefaults["stability"] = (False,self.__optionCallback)
78 optionDefaults["coloring_method"] = ("curve",self.__optionCallback)
79
80 parser = AUTOutil.getAUTORC("AUTO_plotter")
81 optionDefaultsRC = {}
82 c = parseC.parseC()
83 for option in parser.options("AUTO_plotter"):
84 try:
85 optionDefaultsRC[option] = self.parseoption(
86 option,parser.get("AUTO_plotter",option),c)
87 except:
88 optionDefaultsRC[option] = self.parseoption(
89 option,parser.get("AUTO_plotter",option,raw=True),c)
90 # Let these override the RC options, if specified.
91 for key in ["hide","xlabel","ylabel","zlabel"]:
92 if key in kw:
93 optionDefaultsRC[key] = kw[key]
94
95 self.__needsPlot = None
96 grapher.GUIGrapher.__init__(self,parent,**optionDefaultsRC)
97
98 self.addOptions(**optionDefaults)
99 self.addRCOptions(**optionDefaultsRC)
100 for options in [optionDefaultsRC, kw]:
101 if "letter_symbols" in options:
102 self.__optionCallback("letter_symbols",
103 options["letter_symbols"], options)
104 del options["letter_symbols"]
105 plotter._configNoDraw(self,**optionDefaultsRC)
106 plotter._configNoDraw(self,**kw)
107 self._plotNoDraw()
108 self.__needsPlot = None
109 for coord in 'x', 'y', 'z':
110 if "min"+coord not in kw or "max"+coord not in kw:
111 self.computeRange(coord,kw.get("min"+coord),
112 kw.get("max"+coord))
113 grapher.GUIGrapher.plot(self)
114
115 def parselist(self,option,v,c,sep):
116 quote = ' '
117 i = 0
118 vlist = []
119 level = 0
120 for j, ch in enumerate(v):
121 if ch == '[' and level == 0 and option[-9:] == "_defaults":
122 level += 1
123 vlist1 = []
124 i = j+1
125 continue
126 if level == 1 and quote == ' ' and ch == ']':
127 s = v[i:j]
128 i = j+1
129 elif j == len(v) - 1:
130 s = v[i:]
131 elif ch in sep and quote == ' ':
132 s = v[i:j]
133 i = j+1
134 else:
135 if quote == ' ':
136 if ch in ['"',"'"]:
137 quote = ch
138 elif ch == quote:
139 quote = ' '
140 continue
141 s = s.strip()
142 if len(s) == 0 or s[0] not in ['"',"'"]:
143 try:
144 int(s)
145 except ValueError:
146 s = "'"+s+"'"
147 if level == 1:
148 vlist1.append(s)
149 if ch == ']':
150 level -= 1
151 vlist1 = c.scanvalue("["+",".join(vlist1)+"]")[0]
152 for i1, l1 in enumerate(vlist1):
153 try:
154 vlist1[i1] = int(l1)
155 except ValueError:
156 pass
157 vlist.append(vlist1)
158 elif option[-9:] != "_defaults":
159 vlist.append(s)
160 if option[-9:] == "_defaults":
161 return vlist
162 v = c.scanvalue("["+",".join(vlist)+"]")[0]
163 for i, l in enumerate(v):
164 try:
165 v[i] = int(l)
166 except ValueError:
167 pass
168 return v
169
170 def parseoption(self,option,v,c):
171 special = {'None': None, 'True': True, 'False': False,
172 'Yes': True, 'No': False}
173 i = 0
174 quoted = False
175 while i < len(v) and v[i] in ['"',"'"]:
176 q = v[i]
177 # look for endquote
178 j = v.find(q,i+1)
179 if j < 0:
180 break
181 # remove quotes
182 quoted = True
183 v = v[:i]+v[i+1:j]+v[j+1:]
184 i = j - 1
185 # remove comment after last quote
186 i = v.find('#',i+1)
187 if i >= 0:
188 v = v[:i].strip()
189 if quoted:
190 return v
191 w = v.capitalize()
192 if w in special:
193 v = special[w]
194 elif (option[-2:] in ['_x','_y','_z'] or
195 option[-9:] == "_defaults" or
196 option[-11:] == "_coordnames" or
197 option in ["label","index","dashes","labelnames"] or
198 (option[0] == 'd' and len(option) == 2)):
199 # convert to list, quote args if not numbers,
200 # then use the same method as for constant files
201 if ((option[0] == 'd' and len(option) == 2) or
202 option == "labelnames"):
203 brackets = ['{']
204 sep = [',',':']
205 else:
206 brackets = ['[','(']
207 sep = [',']
208 if len(v) > 0 and v[0] in brackets:
209 endbracket = {'{':'}','[':']','(':')'}[v[0]]
210 v = v[1:]
211 if len(v) > 0 and v[-1] == endbracket:
212 v = v[:-1]
213 v = self.parselist(option,v,c,sep)
214 if ((option[0] == 'd' and len(option) == 2) or
215 option == "labelnames"):
216 v = dict([(v[i],v[i+1]) for i in range(0,len(v),2)])
217 if option != "labelnames":
218 # Convert "True"/"False"/"yes"/"no" to True/False
219 for k in v:
220 try:
221 w = v[k].capitalize()
222 if w in special:
223 v[k] = special[w]
224 except AttributeError:
225 pass
226 else: # simple value
227 try:
228 v = int(v)
229 except ValueError:
230 try:
231 v = float(v)
232 except ValueError:
233 pass
234 return v
235
236 def config(self,cnf=None,**kw):
237 rval = self._configNoDraw(cnf,**kw)
238 if isinstance(cnf, str) or (cnf is None and not kw):
239 return rval
240 if 'auto.graphics.grapher_mpl' not in sys.modules and not hasattr(self, "tk"):
241 # plotting disabled
242 return
243 if self.__needsPlot:
244 self._plotNoDraw()
245 self.__needsPlot = None
246 self.clear()
247 self.computeXRange()
248 self.computeYRange()
249 self.computeZRange()
250 grapher.GUIGrapher.plot(self)
251 else:
252 self.clear()
253 self.draw()
254 self.update()
255
256 configure=config
257
258 def _configNoDraw(self,cnf=None,**kw):
259 return grapher.GUIGrapher._configNoDraw(self,cnf,**kw)
260 _configureNoDraw = _configNoDraw
261
262 def __optionCallback(self,key,value,options):
263 gc.collect()
264 if key == "runner":
265 self.cget("bifurcation_diagram").read(value.getBifurcation_diagram())
266 self.cget("solution").read(value.getSolution())
267 elif key == "bifurcation_diagram_filename":
268 try:
269 self.cget("bifurcation_diagram").readFilename(value)
270 except IOError:
271 pass
272 elif key == "solution_filename":
273 try:
274 self.cget("solution").readFilename(value)
275 except IOError:
276 pass
277 if self.cget("label") != [0]:
278 self.__optionCallback("label",self.cget("label"),options)
279 elif key == "solution":
280 if self.cget("label") != [0]:
281 self.__optionCallback("label",self.cget("label"),options)
282 elif key == "label":
283 labels = self.cget("solution").getLabels()
284 if not isinstance(value, (list, tuple)):
285 value = [value]
286 if value in [["all"], ["All"]]:
287 value = labels
288 options["index"] = [j for v in value
289 for j, l in enumerate(labels) if l == v]
290 elif key == "index":
291 labels = self.cget("solution").getLabels()
292 if not isinstance(value, (list, tuple)):
293 value = [value]
294 options["label"] = [labels[v] for v in value]
295 elif key in ["bifurcation_x","bifurcation_y","bifurcation_z",
296 "solution_x","solution_y","solution_z"]:
297 if not isinstance(value, (list, tuple)):
298 value = [value]
299 elif key == "letter_symbols":
300 keys = ["bifurcation_symbol", "limit_point_symbol",
301 "hopf_symbol", "period_doubling_symbol","torus_symbol",
302 "user_point_symbol", "error_symbol",
303 "1_1_resonance_symbol", "1_2_resonance_symbol",
304 "1_3_resonance_symbol", "1_4_resonance_symbol",
305 "bogdanov_takens_symbol", "cusp_symbol",
306 "generalized_hopf_symbol", "zero_hopf_symbol",
307 "fold_flip_symbol", "fold_torus_symbol",
308 "flip_torus_symbol", "torus_torus_symbol"]
309 if value:
310 values = ["B", "L", "H", "D", "T", "U", "X",
311 "R1", "R2", "R3", "R4", "BT", "CP", "GH", "ZH",
312 "LPD", "LTR", "PTR", "TTR"]
313 else:
314 values = ["square", None,
315 "fillsquare", "diamond", "filldiamond",
316 None, None,
317 "filldiamond", "filldiamond",
318 "filldiamond", "filldiamond",
319 "circle", None,
320 "triangle", "doubletriangle",
321 "doubletriangle", "doubletriangle",
322 "doubletriangle", "doubletriangle"]
323 options.update(dict(zip(keys, values)))
324
325 # We only recreate the data if one of the above options gets set
326 # We can't just recreate the data for any option since:
327 # 1) It is inefficient
328 # 2) The range gets recomputed when we create new data, so
329 # minx, miny, maxx, and maxy all never get used.
330 self.__needsPlot = "yes"
331
332 def _plotNoDraw(self):
333 self.delAllData()
334 ty = self.cget("type")
335 columns = [self.cget(ty+"_x"),self.cget(ty+"_y"),self.cget(ty+"_z")]
336 for coord in range(3):
337 if (type(columns[coord]) != type([]) and
338 type(columns[coord]) != type(())):
339 columns[coord] = [columns[coord]]
340 names, columns = self.__makeaxistitles(*columns)
341 m = max([len(column) for column in columns])
342 for coord, column in enumerate(columns):
343 if column is not None and len(column) == 1:
344 columns[coord] = column * m
345 plot = True
346 if ty == "bifurcation":
347 sol = self.cget(ty+"_diagram")
348 else:
349 sol = self.cget(ty)
350 if ty == "bifurcation" and len(sol) and len(sol[0]):
351 self.__plot7(*columns)
352 elif ty == "solution" and len(sol) > 0:
353 self.__plot8(*columns)
354 else:
355 plot = False
356 if plot:
357 label = {}
358 for coord in "x","y","z":
359 label[coord] = self[coord+"label"]
360 if self.config(coord+"label")[3] is None:
361 namescoord = names[{"x": 0, "y": 1, "z": 2}[coord]]
362 if namescoord is None:
363 label["z"] = None
364 else:
365 label[coord] = ", ".join(namescoord)
366 grapher.GUIGrapher._configNoDraw(self,xlabel=label["x"],
367 ylabel=label["y"],
368 zlabel=label["z"])
369
370 def plot(self):
371 self._plotNoDraw()
372 self.clear()
373 self.computeXRange()
374 self.computeYRange()
375 self.computeZRange()
376 grapher.GUIGrapher.plot(self)
377 self.draw()
378
379 def __makeaxistitles(self,xcolumns,ycolumns,zcolumns):
380 # parse coordinate names from bifurcation diagram/solution
381 # then construct the titles from these names
382 ty = self.cget("type")
383 indepvarname = None
384 if ty == "bifurcation":
385 solution = self.cget(ty+"_diagram")
386 # use the "branches" member for parseB objects
387 solution = getattr(solution,"branches",solution)
388 else:
389 solution = self.cget(ty)
390 parsecoordnames = []
391 # first go by column
392 for s in solution:
393 # check for any "MAX"-style member and replace, e.g., U(1) by
394 # MAX U(1)
395 if ty == "bifurcation":
396 for i in range(min(len(parsecoordnames),len(s.coordnames))):
397 name = s.coordnames[i]
398 namelist = name.split(None,1)
399 if (len(namelist) > 1 and
400 namelist[0] in ["MAX", "MIN", "INTEGRAL", "L2-NORM"] and
401 parsecoordnames[i] == namelist[1].strip()):
402 parsecoordnames[i] = name.strip()
403 elif indepvarname is None:
404 indepvarname = s.indepvarname
405 if len(s.coordnames) > len(parsecoordnames):
406 parsecoordnames.extend([name.strip() for name in
407 s.coordnames[len(parsecoordnames):]])
408 # then add anything not already there
409 for s in solution:
410 for name in s.coordnames:
411 sname = name.strip()
412 if sname not in parsecoordnames:
413 parsecoordnames.append(sname)
414
415 # override coordnames with user/autorc provided ones
416 if ty == "solution":
417 if self.cget("solution_indepvarname"):
418 indepvarname = self.cget("solution_indepvarname")
419 elif indepvarname is None:
420 indepvarname = "t"
421 coordnames = self.cget(ty+"_coordnames") or []
422 coordnames = coordnames[:]
423 # but if that list is too short, extend it
424 if len(coordnames) < len(parsecoordnames):
425 coordnames.extend(parsecoordnames[len(coordnames):])
426 self._coordnames = coordnames
427
428 # construct translation dictionary for unames/parnames in autorc
429 labelnames = self.cget("labelnames") or {}
430 labelnames = labelnames.copy()
431 for key in list(labelnames):
432 for prefix in "MIN ", "MAX ", "INTEGRAL ", "L2-NORM ":
433 if prefix+key not in labelnames:
434 labelnames[prefix+key] = prefix+labelnames[key]
435
436 # construct titles
437 names = [["Error"],["Error"]]
438 lx = len(xcolumns)
439 ly = len(ycolumns)
440 lz = len(zcolumns)
441 if lx == 1: lx = max(ly, lz)
442 if ly == 1: ly = max(lx, lz)
443 if lz == 1: lz = max(lx, ly)
444 if (len(solution) > 0 and lx == ly == lz and
445 (ty == "solution" or len(solution[0]) > 0)):
446 names = [[],[],[]]
447 for j in range(3):
448 columns = [xcolumns,ycolumns,zcolumns][j]
449 for col in columns:
450 if col is None:
451 names[j] = None
452 continue
453 if type(col) == type(1):
454 # numerical column: check limits
455 if indepvarname is not None and col == -1:
456 col = indepvarname
457 else:
458 for s in solution:
459 if col < len(s.coordnames):
460 col = coordnames[col]
461 break
462 if type(col) == type(1):
463 print("The %s-coordinate (set to column %s) "
464 "is out of range"%(["x","y","z"][j],col))
465 col = "Error"
466 elif col not in coordnames and (indepvarname is None or
467 col != indepvarname):
468 print("Unknown column name: %s"%(col))
469 col = "Error"
470 names[j].append(labelnames.get(col, col))
471
472 # translate xcolumns/ycolumns to use parsed coordnames
473 ucoordnames = self.cget(ty+"_coordnames") or []
474 cols = [xcolumns,ycolumns,zcolumns]
475 if ucoordnames != []:
476 cols = []
477 for columns in [xcolumns,ycolumns,zcolumns]:
478 ncol = []
479 for col in columns:
480 try:
481 indx = ucoordnames.index(col)
482 col = parsecoordnames[indx]
483 except (ValueError, TypeError):
484 pass
485 ncol.append(col)
486 cols.append(ncol)
487 return names,cols
488
489 def __plot7branch(self,branch,xcolumns,ycolumns,zcolumns):
490 symbollist = [
491 [[1,6], "bifurcation_symbol"],
492 [[2,5], "limit_point_symbol"],
493 [[3], "hopf_symbol"],
494 [[-1], "bogdanov_takens_symbol"],
495 [[-2], "cusp_symbol"],
496 [[-32], "generalized_hopf_symbol"],
497 [[-3], "zero_hopf_symbol"],
498 [[7], "period_doubling_symbol"],
499 [[8], "torus_symbol"],
500 [[-5], "1_1_resonance_symbol"],
501 [[-6], "1_2_resonance_symbol"],
502 [[-7], "1_3_resonance_symbol"],
503 [[-8], "1_4_resonance_symbol"],
504 [[23,83], "fold_torus_symbol"],
505 [[77,87], "flip_torus_symbol"],
506 [[28,78], "fold_flip_symbol"],
507 [[88], "torus_torus_symbol"],
508 [[-4], "user_point_symbol"]]
509 specialsymbols = [-32,23,83,77,87,28,78,88]
510 dp = self.cget("stability")
511 coordnames = branch.coordnames
512 for j in range(len(xcolumns)):
513 labels = []
514 for i,l in branch.labels.sortByIndex():
515 label = None
516 for k in l:
517 v = l[k]
518 if "LAB" in v:
519 label = v
520 break
521 if label is None:
522 continue
523 lab = label["LAB"]
524 TYnumber = label["TY number"]
525 if TYnumber not in specialsymbols:
526 if TYnumber>=0:
527 TYnumber=TYnumber%10
528 else:
529 TYnumber=-((-TYnumber)%10)
530 text = ""
531 if lab != 0:
532 text = str(lab)
533 symbol = None
534 for item in symbollist:
535 if TYnumber in item[0]:
536 symbol = item[1]
537 if symbol is not None:
538 symbol = self.cget(symbol)
539 elif TYnumber not in [0,4,9]:
540 symbol = self.cget("error_symbol")
541 labels.append([i, text, symbol])
542 xycols = []
543 for col in [xcolumns[j],ycolumns[j],zcolumns[j]]:
544 if col is None:
545 break
546 if type(col) != type(1):
547 try:
548 col = coordnames.index(col)
549 except ValueError:
550 # check if we have an item that starts with
551 # MAX, MIN, INTEGRAL, or L2-NORM
552 # in that case also plot U(1) if given MAX U(1)
553 namelist = col.split(None,1)
554 if len(namelist) < 2 or (namelist[0] not in
555 ["MAX", "MIN", "INTEGRAL", "L2-NORM"]):
556 break
557 try:
558 col = coordnames.index(namelist[1])
559 except ValueError:
560 break
561 try:
562 xy = branch.coordarray[col]
563 except IndexError:
564 break
565 xycols.append(xy)
566 if len(xycols) < 2 or (zcolumns[j] is not None and len(xycols) < 3):
567 continue
568 [x,y] = xycols[:2]
569 if len(xycols) == 3:
570 z = xycols[2]
571 else:
572 z = None
573 if self.cget("coloring_method") == "branch":
574 color = abs(branch.BR)-1
575 elif self.cget("coloring_method") == "type":
576 color = branch.TY
577 else:
578 color = None
579 if dp:
580 #look at stability:
581 newsect = 1
582 old = 0
583 stability = branch.stability()
584 addedlabels = []
585 for pt in stability:
586 abspt = abs(pt)
587 if abspt > 1 or pt == stability[-1]:
588 if z is None:
589 v = x[old:abspt],y[old:abspt]
590 else:
591 v = x[old:abspt],y[old:abspt],z[old:abspt]
592 self.addArrayNoDraw(v,newsect,color,stable=pt<0)
593 for label in labels:
594 if (old <= label[0] and label[0] < abspt and
595 label not in addedlabels):
596 self.addLabel(len(self)-1, label[0] - old,
597 label[1], label[2])
598 addedlabels.append(label)
599 old = abspt - 1
600 newsect = 0
601 else:
602 if z is None:
603 self.addArrayNoDraw((x,y),1,color)
604 else:
605 self.addArrayNoDraw((x,y,z),1,color)
606 for label in labels:
607 self.addLabel(len(self)-1, *label)
608
609 def __plot7(self,xcolumns,ycolumns,zcolumns):
610 self.delAllData()
611 solution = self.cget("bifurcation_diagram")
612 branches = getattr(solution,"branches",solution)
613 if len(xcolumns) == len(ycolumns) == len(zcolumns):
614 for branch in branches:
615 self.__plot7branch(branch,xcolumns,ycolumns,zcolumns)
616
617 def __plot8solution(self,sol,index,xcolumns,ycolumns,zcolumns):
618 indepvarname = sol.indepvarname
619 tm = sol[indepvarname]
620 label = sol["Label"]
621 if self.cget("solution_indepvarname"):
622 indepvarname = self.cget("solution_indepvarname")
623 coordnames = sol.coordnames
624 if self.cget("coloring_method") == "branch":
625 color = sol["BR"]-1
626 elif self.cget("coloring_method") == "type":
627 color = sol["TY number"]
628 else:
629 color = None
630 for j in range(len(xcolumns)):
631 labels = []
632 xycols = []
633 for col in [xcolumns[j],ycolumns[j],zcolumns[j]]:
634 if type(col) != type(1):
635 if indepvarname == col:
636 col = -1
637 else:
638 try:
639 col = coordnames.index(col)
640 except ValueError:
641 break
642 if col == -1:
643 xy = tm
644 else:
645 try:
646 xy = sol.coordarray[col]
647 except IndexError:
648 break
649 xycols.append(xy)
650 if len(xycols) < 2:
651 continue
652 [x,y] = xycols[:2]
653 z = None
654 if len(xycols) == 3:
655 z = xycols[2]
656 if not(self.cget("mark_t") is None):
657 for i in range(len(tm)):
658 if i != 0 and tm[i-1] <= self.cget("mark_t") < tm[i]:
659 labels.append({"index": i,
660 "text": "",
661 "symbol": "fillcircle"})
662 if len(tm) <= 15:
663 index = 1
664 if len(tm) <= 1:
665 index = 0
666 labels.append({"index": index, "text": str(label), "symbol": ""})
667 # Call the base class config
668 if len(x) > 0:
669 if z is None:
670 self.addArrayNoDraw((x,y),color=color)
671 else:
672 self.addArrayNoDraw((x,y,z),color=color)
673 for lab in labels:
674 self.addLabel(len(self)-1, lab["index"], lab["text"],
675 lab["symbol"])
676
677 index = index + 10
678 if index > len(tm):
679 index = 14
680 return index
681
682 def __plot8(self,xcolumns,ycolumns,zcolumns):
683 self.delAllData()
684 solution = self.cget("solution")
685 if len(xcolumns) == len(ycolumns) == len(zcolumns):
686 index = 9
687 for ind in self.cget("index"):
688 sol = solution.getIndex(ind)
689 index = self.__plot8solution(sol,index,xcolumns,ycolumns,
690 zcolumns)
691
692
693
694 def test():
695 from auto import parseB
696 from auto import parseS
697 import sys
698 foo = plotter(bifurcation_diagram_filename="../test_data/fort.7",
699 solution_filename="../test_data/fort.8")
700
701 foo.plot()
702 foo.pack()
703 foo.update()
704 print("Hit return to continue")
705 raw_input()
706 foo.clear()
707 foo.update()
708 print("Hit return to continue")
709 raw_input()
710 foo.clear()
711 foo.config(type="solution",label=[6])
712 foo.plot()
713 foo.update()
714 print("Hit return to continue")
715 raw_input()
716 foo.clear()
717 foo.config(index=[3])
718 foo.plot()
719 foo.update()
720 print("Hit return to continue")
721 raw_input()
722
723 if __name__ == "__main__":
724 test()
725
726
727
728
729