← Back to team overview

yade-dev team mailing list archive

[svn] r1869 - in trunk: py scripts

 

Author: eudoxos
Date: 2009-07-15 18:46:34 +0200 (Wed, 15 Jul 2009)
New Revision: 1869

Modified:
   trunk/py/plot.py
   trunk/scripts/simple-scene-graph.py
Log:
1. Fix non-tuple in graph specification
2. Allow plotting agains the y2 axis, after a special parameter '|||'. 



Modified: trunk/py/plot.py
===================================================================
--- trunk/py/plot.py	2009-07-15 16:10:16 UTC (rev 1868)
+++ trunk/py/plot.py	2009-07-15 16:46:34 UTC (rev 1869)
@@ -78,9 +78,14 @@
 		if name in d: data[name].append(d[name]) #numpy.append(data[name],[d[name]],1)
 		else: data[name].append(nan)
 
-def fillNonSequence(o):
-	if o.__class__==tuple().__class__ or o.__class__==list().__class__: return o
+def addPointTypeSpecifier(o):
+	"""Add point type specifier to simple variable name"""
+	if type(o) in [tuple,list]: return o
 	else: return (o,'')
+def tuplifyYAxis(pp):
+	"""convert one variable to a 1-tuple"""
+	if type(pp) in [tuple,list]: return pp
+	else: return (pp,)
 
 def show(): plot()
 
@@ -88,10 +93,22 @@
 	pylab.ion() ## # no interactive mode (hmmm, I don't know why actually...)
 	for p in plots:
 		pylab.figure()
-		plots_p=[fillNonSequence(o) for o in plots[p]]
+		plots_p=[addPointTypeSpecifier(o) for o in tuplifyYAxis(plots[p])]
 		plotsFilled[p]=plots_p
-		plotLines[p]=pylab.plot(*sum([[data[p],data[d[0]],d[1]] for d in plots_p],[]))
-		pylab.legend([_p[0] for _p in plots_p])
+		plots_p_y1,plots_p_y2=[],[]; y1=True
+		for d in plots_p:
+			if d[0]=='|||':
+				y1=False; continue
+			if y1: plots_p_y1.append(d)
+			else: plots_p_y2.append(d)
+		plotLines[p]=pylab.plot(*sum([[data[p],data[d[0]],d[1]] for d in plots_p_y1],[]))
+		pylab.legend([_p[0] for _p in plots_p_y1],loc=('upper left' if len(plots_p_y2)>0 else 'best'))
+		pylab.ylabel(','.join([_p[0] for _p in plots_p_y1]))
+		if len(plots_p_y2)>0:
+			pylab.twinx()
+			plotLines[p]+=[pylab.plot(*sum([[data[p],data[d[0]],d[1]] for d in plots_p_y2],[]))]
+			pylab.legend([_p[0] for _p in plots_p_y2],loc='upper right')
+			pylab.ylabel(','.join([_p[0] for _p in plots_p_y2]))
 		pylab.xlabel(p)
 		if 'title' in O.tags.keys(): pylab.title(O.tags['title'])
 	pylab.show()

Modified: trunk/scripts/simple-scene-graph.py
===================================================================
--- trunk/scripts/simple-scene-graph.py	2009-07-15 16:10:16 UTC (rev 1868)
+++ trunk/scripts/simple-scene-graph.py	2009-07-15 16:46:34 UTC (rev 1869)
@@ -57,7 +57,7 @@
 ## we will have 2 plots:
 ## 1. t as function of i (joke test function)
 ## 2. z_sph and v_sph (rendered as green triangles, 'g^') as function of t
-yade.plot.plots={'i':('t'),'t':('z_sph',('v_sph','g^'))}
+yade.plot.plots={'i':('t'),'t':('z_sph','|||',('v_sph','go-'))}
 
 ## static var to specify max number of samples we want to have (1000 is default, no change)
 # yade.plot.maxDataLen=1000
@@ -79,3 +79,4 @@
 to see figures.
 """
 import yade.plot as yp
+yp.plot()