Matplotlib: Exercises


3. Creating a Scatter Plot. In Matplotlib, you can create a scatter plot to visualize individual data points. You can use the plt.scatter() function to create scatter plots.

For example, you can create a scatter plot of x and y values like this: import matplotlib.pyplot as plt; plt.scatter(x, y).

In the exercise below, you will create a scatter plot.


# Import the Matplotlib library import matplotlib.pyplot as plt # Create x and y values for a scatter plot x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # Create a scatter plot plt.scatter(___) # Display the plot plt.show() # Import the Matplotlib library import matplotlib.pyplot as plt # Create x and y values for a scatter plot x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # Create a scatter plot plt.scatter(x, y) # Display the plot plt.show() test_object("x") test_object("y") success_msg("Correct!")
To create a scatter plot, import Matplotlib and use plt.scatter() with x and y values.

Previous Exercise Next Exercise