from subprocess import check_output, Popen, PIPE, STDOUT
import StringIO
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation

def GenPoints(lines):
    """
    Create a line using points list

    length is the number of points for the line.
    lines is the points list.
    """
    ll = len(lines)
    linePoints = np.empty((3, ll))
    for index in range(0, ll):
        line = lines[index].rstrip().split(',')
        linePoints[0][index] = float(line[0])
        linePoints[1][index] = float(line[1])
        linePoints[2][index] = float(line[2])
    return linePoints

def UpdateLines(num, dataLines, lines):
    # for line, data in zip(lines, dataLines):
        # NOTE: there is no .set_data() for 3 dim data...
    lines.set_data(dataLines[0:2, :num])
    lines.set_3d_properties(dataLines[2, :num])
    # return lines

# read stdout from target program
ps = Popen(('./silhouette line/line-1d-1490089995240.csv'), shell=True, stdout=PIPE, stderr=STDOUT)
output, err = ps.communicate()

# readline from the output string
buf = StringIO.StringIO(output)
lines = buf.readlines()
points = GenPoints(lines)

fig = plt.figure()
ax = p3.Axes3D(fig)
axlines = ax.plot(points[0, 0:1], points[1, 0:1], points[2, 0:1])[0]

# Setting the axes properties
axUpper = int(np.max(points) + 1)
axLower = int(np.min(points) - 1)
ax.set_xlim3d([axLower, axUpper])
ax.set_xlabel('X')

ax.set_ylim3d([axLower, axUpper])
ax.set_ylabel('Y')

ax.set_zlim3d([axLower, axUpper])
ax.set_zlabel('Z')

ax.set_title('3D Test')
print points
print lines
if 0 == len(points):
    # Creating the Animation object
    line_ani = animation.FuncAnimation(fig, UpdateLines, len(lines), fargs=(points, axlines),
                                       interval=50, blit=False)

plt.show()

@@ -266,17 +266,16 @@
 ts list%0A
-%0A
     leng
@@ -1582,40 +1582,11 @@
 t')%0A
-print points%0Aprint lines%0Aif 0 ==
+%0Aif
  len
@@ -1593,16 +1593,21 @@
 (points)
+ != 0
 :%0A    # 
@@ -1730,20 +1730,16 @@
 lines),%0A
-    
         

fix the bug if-statement on wether executing the animation function.