Q1. Scenario: You have months = [''Jan'',''Feb'',''Mar''] and sales = [200, 250, 300]. Create a line plot using matplotlib. Label axes and add title.
import matplotlib.pyplot as plt; plt.plot(months, sales); plt.xlabel(''Month''); plt.ylabel(''Sales''); plt.title(''Monthly Sales''); plt.show(). Line plots show trends over time.
Q2. Scenario: Display a bar chart of product sales: products = [''A'',''B'',''C'']; values = [30, 45, 25]. Use plt.bar and customize colors.
plt.bar(products, values, color=[''red'',''green'',''blue'']); plt.title(''Product Sales''); plt.show(). Bar charts compare categorical data. Horizontal bar: plt.barh.
Q3. Scenario: Overlay two line plots on same axes: actual vs predicted values over 10 epochs. Add legend.
epochs = range(1,11); actual = [0.9,0.85,0.8,0.78,0.75,0.73,0.7,0.68,0.65,0.63]; pred = [0.92,0.88,0.82,0.79,0.76,0.74,0.71,0.69,0.66,0.64]; plt.plot(epochs, actual, label=''Actual''); plt.plot(epochs, pred, label=''Predicted''); plt.legend(); plt.show().
Q4. Scenario: Create a grouped bar chart comparing two groups across categories. Use numpy to set bar positions.
import numpy as np; categories = [''A'',''B'',''C'']; group1 = [15,20,25]; group2 = [10,18,22]; x = np.arange(len(categories)); width = 0.35; plt.bar(x-width/2, group1, width, label=''Group1''); plt.bar(x+width/2, group2, width, label=''Group2''); plt.xticks(x, categories); plt.legend(); plt.show().
Q5. Scenario: Save a plot to a file 'plot.png' with high dpi.
plt.savefig(''plot.png'', dpi=300, bbox_inches=''tight'') before plt.show(). bbox_inches=''tight'' removes extra whitespace. Use format=''pdf'' for vector graphics.
