I have a function
np.sin(x / 2.) * np.exp(x / 4.) + 6. * np.exp(-x / 4.)
and I can plot it by using following code:
x = np.arange(-5, 15, 2)
y = np.sin(x / 2.) * np.exp(x / 4.) + 6. * np.exp(-x / 4.)
plt.plot(x, y)
plt.show()
but if I define function plotting doesn't work:
rr = np.arange(-5, 15, 2)
def y(o):
return np.sin(o / 2.) * np.exp(o / 4.) + 6. * np.exp(-o / 4.)
def h(b):
return int(y(b))
plt.plot(rr, h)
plt.show()
Why does it happen, and how could I change the code to plot the function?
Try this instead:
import numpy as np
import matplotlib.pyplot as plt
rr = np.arange(-5, 15, 2)
def y(o):
return np.sin(o / 2.) * np.exp(o / 4.) + 6. * np.exp(-o / 4.)
plt.plot(rr, y(rr).astype(np.int))
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With