Complete the code to plot a simple line graph of y values.
import matplotlib.pyplot as plt y = [1, 3, 2, 4] plt.[1](y) plt.show()
The plt.plot() function draws a line graph connecting the points in the list y.
Complete the code to plot x and y values as a line graph.
import matplotlib.pyplot as plt x = [0, 1, 2, 3] y = [1, 3, 2, 4] plt.plot([1], y) plt.show()
The plt.plot() function needs both x and y values to plot points correctly. Here, x is the list of x-coordinates.
Fix the error in the code to plot x and y values with a red dashed line.
import matplotlib.pyplot as plt x = [0, 1, 2, 3] y = [1, 3, 2, 4] plt.plot(x, y, [1]) plt.show()
The string 'r--' tells matplotlib to plot a red dashed line. The order matters: color first, then line style.
Fill both blanks to create a plot with x and y values and label the x-axis.
import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5, 6] plt.[1](x, y) plt.[2]('Time (s)') plt.show()
ylabel instead of xlabel for the x-axis label.plt.plot() draws the line graph. plt.xlabel() adds a label to the x-axis.
Fill all three blanks to create a plot with x and y, add a title, and label the y-axis.
import matplotlib.pyplot as plt x = [0, 1, 2] y = [3, 1, 4] plt.[1](x, y) plt.[2]('Sample Plot') plt.[3]('Value') plt.show()
xlabel and ylabel.plt.plot() draws the line graph, plt.title() adds the plot title, and plt.ylabel() labels the y-axis.