77
88import numpy as np
99import matplotlib .pyplot as plt
10- import mpl_toolkits .mplot3d .axes3d as p3
1110import matplotlib .animation as animation
1211
1312# Fixing random state for reproducibility
1413np .random .seed (19680801 )
1514
1615
17- def Gen_RandLine (length , dims = 2 ):
16+ def gen_rand_line (length , dims = 2 ):
1817 """
1918 Create a line using a random walk algorithm
2019
2120 length is the number of points for the line.
2221 dims is the number of dimensions the line has.
2322 """
24- lineData = np .empty ((dims , length ))
25- lineData [:, 0 ] = np .random .rand (dims )
23+ line_data = np .empty ((dims , length ))
24+ line_data [:, 0 ] = np .random .rand (dims )
2625 for index in range (1 , length ):
2726 # scaling the random numbers by 0.1 so
2827 # movement is small compared to position.
2928 # subtraction by 0.5 is to change the range to [-0.5, 0.5]
3029 # to allow a line to move backwards.
31- step = ((np .random .rand (dims ) - 0.5 ) * 0.1 )
32- lineData [:, index ] = lineData [:, index - 1 ] + step
33-
34- return lineData
30+ step = (np .random .rand (dims ) - 0.5 ) * 0.1
31+ line_data [:, index ] = line_data [:, index - 1 ] + step
32+ return line_data
3533
3634
3735def update_lines (num , dataLines , lines ):
@@ -41,12 +39,13 @@ def update_lines(num, dataLines, lines):
4139 line .set_3d_properties (data [2 , :num ])
4240 return lines
4341
42+
4443# Attaching 3D axis to the figure
4544fig = plt .figure ()
46- ax = p3 . Axes3D ( fig )
45+ ax = fig . add_subplot ( projection = "3d" )
4746
4847# Fifty lines of random 3-D lines
49- data = [Gen_RandLine (25 , 3 ) for index in range (50 )]
48+ data = [gen_rand_line (25 , 3 ) for index in range (50 )]
5049
5150# Creating fifty line objects.
5251# NOTE: Can't pass empty arrays into 3d version of plot()
@@ -65,7 +64,7 @@ def update_lines(num, dataLines, lines):
6564ax .set_title ('3D Test' )
6665
6766# Creating the Animation object
68- line_ani = animation .FuncAnimation (fig , update_lines , 25 , fargs = ( data , lines ),
69- interval = 50 , blit = False )
67+ line_ani = animation .FuncAnimation (
68+ fig , update_lines , 25 , fargs = ( data , lines ), interval = 50 )
7069
7170plt .show ()
0 commit comments