5. You have a DataFrame with sales data for two products over 3 months. You want to plot both lines on the same chart with a title, axis labels, and a legend. Which code snippet correctly adds all these elements?
import pandas as pd
import matplotlib.pyplot as plt
data = {'Month': ['Jan', 'Feb', 'Mar'], 'ProductA': [100, 120, 130], 'ProductB': [90, 110, 115]}
df = pd.DataFrame(data)
# Which code below is correct?
A: plt.plot(df['Month'], df['ProductA'], label='Product A')
plt.plot(df['Month'], df['ProductB'], label='Product B')
plt.title('Sales Over Months')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.legend()
plt.show()
B: plt.plot(df['ProductA'], df['Month'], label='Product A')
plt.plot(df['ProductB'], df['Month'], label='Product B')
plt.title('Sales Over Months')
plt.xlabel('Sales')
plt.ylabel('Month')
plt.legend()
plt.show()
C: plt.plot(df['Month'], df['ProductA'])
plt.plot(df['Month'], df['ProductB'])
plt.title('Sales Over Months')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.show()
D: plt.plot(df['Month'], df['ProductA'], label='Product A')
plt.plot(df['Month'], df['ProductB'], label='Product B')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.show()