w3resource
NumPy Exercises

NumPy: Compute the x and y coordinates for points on a sine curve and plot the points using matplotlib

NumPy: Basic Exercise-40 with Solution

Write a NumPy program to compute the x and y coordinates for points on a sine curve and plot the points using matplotlib.

Sample Solution :

Python Code :

import numpy as np
import matplotlib.pyplot as plt
# Compute the x and y coordinates for points on a sine curve
x = np.arange(0, 3 * np.pi, 0.2)
y = np.sin(x)
print("Plot the points using matplotlib:")
plt.plot(x, y)
plt.show()

Sample Output:

NumPy : Plot the points using matplotlib

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to convert a given array into a list and then convert it into a list again.
Next: Write a NumPy program to convert numpy dtypes to native python types.

What is the difficulty level of this exercise?