Browse Source

added 3D projection

epsylon 6 months ago
parent
commit
204c64df0b
1 changed files with 14 additions and 3 deletions
  1. 14 3
      collatz/main.py

+ 14 - 3
collatz/main.py

@@ -9,6 +9,7 @@ Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 """
 import os, sys
 import matplotlib.pyplot as plt
+from mpl_toolkits.mplot3d import Axes3D
 
 plt.rcParams.update({'figure.max_open_warning': 0})
 
@@ -38,10 +39,19 @@ class Collatz(object):
             print('     - Tree =', self.tree)
         plt.figure()
         fig = plt.figure(1)
-        ax = fig.add_subplot(111, facecolor='black')
+        ax = plt.gca(projection="3d")
+        xs = []
+        ys = []
+        zs = []
         for t in self.tree:
-            ax.scatter(self.tree.index(t)+1, t, color="red", s=2)
-        plt.clf() # removing matplot future warning
+            z = float(t)
+            y = z
+            x = y
+            xs.append(x)
+            ys.append(y)
+            zs.append(z)
+        ax.scatter(xs,ys,zs, c='red',s=100)
+        ax.plot(xs,ys,zs, color='green')
         header = '"Tree" for number '+str(self.root)+' to becomes 1'
         plt.title(header)
         plt.ylabel('Number(s)')
@@ -62,6 +72,7 @@ class Collatz(object):
             if not self.mode == "l" or self.mode == "L" or self.mode == "Learn" or self.mode == "learn":
                 print("\n[Info] You have this 'tree' secuence previously saved. Exiting...\n")
         ax.clear()
+        plt.clf()
 
     def generate_forest(self, rng):
         srng = rng.split('-')