Matplotlib: Exercises


1. Creating a Basic Line Plot. In Python, Matplotlib is a popular library for creating visualizations. You can create a basic line plot by importing the Matplotlib library and using the plt.plot() function.

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

In the exercise below, you will generate a line plot.


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

Previous Exercise Next Exercise