Python: np.vectorize to return "float"

Viewed 1623

Running the following code:

import matplotlib.pyplot as plt
import numpy as np

def xon (ton, t):
    if ton <= t:
        return (t-ton)/5
    else:
        return 0

vxon = np.vectorize(xon)
t = np.linspace(0, 49, 50)    
xontest = vxon(0, t)
plt.plot(t, xontest, '-')
plt.show()

I get the plot: enter image description here

But when I try to plot for values of ton, wchich are different than zero, e.g.:

xontest = vxon(2, t)

the plot seems to round all the xon values to integer:

enter image description here

What in my code causes such behaviour?

1 Answers
Related