You can use numpy.arange
:
>>> np.arange(0, 2*math.pi, math.pi/100)
array([ 0. , 0.03141593, 0.06283185, 0.09424778, 0.12566371,
# ... 190 more ...
6.12610567, 6.1575216 , 6.18893753, 6.22035345, 6.25176938])
You might also be interested in numpy.linspace
:
>>> np.linspace(0, 2*math.pi, 200)
array([ 0. , 0.0315738 , 0.06314759, 0.09472139, 0.12629518,
# ... 190 more ...
6.15689013, 6.18846392, 6.22003772, 6.25161151, 6.28318531])
Using np.arange
, the third parameter is the step
, while with np.linspace
it's the total number of evenly-spaced values in the interval. Also note that linspace
will include the 2*pi
, while arange
does not, but stop at the last multiple of step
smaller than that.
You can then plot those with matplotlib.pyplot
. For sin
, you can just use np.sin
which will apply the sine function to each element of the input array. For other functions, use a list comprehension.
>>> from matplotlib import pyplot
>>> x = np.arange(0, 2*math.pi, math.pi/100)
>>> y = np.sin(x) # using np.sin
>>> y = [math.sin(r) for r in x] # using list comprehension
>>> pyplot.plot(x, y)
[<matplotlib.lines.Line2D at 0xb3c3210c>]
>>>pyplot.show()