workout decimals

22 views
Skip to first unread message

Luca Scarpelli

unread,
Nov 28, 2019, 11:26:26 PM11/28/19
to spyder
I have a problem in plotting some data from a list; values are not correct and I have to modify them.
this is the plot with the correlated functions:

import timeit
import numpy as np
import matplotlib.pyplot as plt

def factorise(n):
    factors = []
    for i in range(1,n+1):
        if n%i == 0:
            factors.append(i)
    return factors  

print('The following show the time needed to factorise each number in the interval:')

def list_of_times(number):
    times = []
    for i in range(1,number+1): 
        factorise(i)
        t = timeit.repeat('factorise(5)', 'from __main__ import factorise',repeat = 1, number = 1)
        times.append(t)
        print("{} = {} seconds".format(i,t))
    return times

number = 5

list_of_times(number)

#%%
x_values = np.arange(1,6)
print(f'x_values: {x_values}')
y_values = list_of_times(number)  
print(f'y_values: {y_values}')
plt.plot(x_values,y_values)
plt.title('The time exploration function')
plt.ylabel('$\ time(sec)$')
plt.xlabel('$x$')
plt.grid(True)  #These help the visualisation
plt.savefig('y_values_upto'+str(6)+'.png',dpi=100)
plt.show()

Screenshot (7).png



Screenshot (6).png




Screenshot (5).png



as you can see there s so many problems in the graph (i would like integers for x and I don't know why the y axes has these numbers)




Reply all
Reply to author
Forward
0 new messages