Complete the code to plot two lines on the same graph using matplotlib.
import matplotlib.pyplot as plt x = [1, 2, 3] y1 = [2, 4, 6] y2 = [1, 3, 5] plt.plot(x, y1) plt.[1](x, y2) plt.show()
Use plt.plot to plot lines. Here, plt.plot(x, y2) adds the second line.
Complete the code to add labels to each line in the plot.
import matplotlib.pyplot as plt x = [1, 2, 3] y1 = [2, 4, 6] y2 = [1, 3, 5] plt.plot(x, y1, label='Line 1') plt.plot(x, y2, [1]='Line 2') plt.legend() plt.show()
The label argument names each line for the legend.
Fix the error in the code to plot multiple lines with different colors.
import matplotlib.pyplot as plt x = [1, 2, 3] y1 = [2, 4, 6] y2 = [1, 3, 5] plt.plot(x, y1, color='red') plt.plot(x, y2, color='[1]') plt.show()
The color argument must be a valid color name like 'blue'. '3' or 'greenish' are invalid.
Fill both blanks to create a dictionary comprehension that maps each x to its y1 squared, but only if y1 is greater than 3.
result = {x: y1[1]2 for x, y1 in zip(x, y1) if y1 [2] 3}Use ** for power and > to filter values greater than 3.
Fill all three blanks to create a dictionary comprehension that maps each line label to the sum of its y values if the sum is greater than 5.
data = {'Line 1': y1, 'Line 2': y2}
result = [1]: sum([2]) for [1], [2] in data.items() if sum([2]) > 5}Use line for the key variable and values for the list of y values.