#! /usr/bin/env python3 # def collatz_dot_plot ( nmax ): # # Evaluate T(n) for n = 1 through NMAX and plot the results. # from collatz import collatz import matplotlib.pyplot as plt # # Store n and T(n) in lists. # nvec = [] tvec = [] for n in range ( 1, nmax + 1 ): nvec.append ( n ) tn = collatz ( n ) tvec.append ( tn ) plt.clf ( ) plt.plot ( nvec, tvec, 'bo' ) plt.plot ( nvec, nvec, 'r-' ) plt.xlabel ( '<-- n -->' ) plt.ylabel ( '<-- T(n) --.' ) filename = 'collatz_dot_plot.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) return if ( __name__ == '__main__' ): collatz_dot_plot ( 50 )