Reputation: 13
import matplotlib.pyplot as plt
import numpy as np
from math import sin, pi
y = pi
x = np.linspace(0, 3*y, 500)
plt.plot(x, sin(x**2))
title("A simple Graph")
plt.show()
getting
'only length-1 arrays can be converted to Python scalars'
error while running this code
Upvotes: 0
Views: 6750
Reputation: 2086
You may use this code instead:
import matplotlib.pyplot as plt
import numpy as np
from math import sin,pi
y=pi
x = np.linspace(0, 3*y, 500)
plt.plot(x,[sin(_**2) for _ in x])
title("A simple Graph")
plt.show()
The second argument of the plot function was not correct.
Upvotes: 1