QUESTION BANK Unit 3
🟢 Beginner Level
1. What library is most commonly used to create line plots in Python?
2. What function is used to create a basic line plot in matplotlib?
3. Write code to plot the following data as a line graph:
python
CopyEdit
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
4. How do you display a plot after creating it using matplotlib?
5. How do you label the x-axis and y-axis in a line plot?
🟡 Intermediate Level
6. What does plt.plot(x, y, 'r--') do?
7. How can you add a title to your plot?
8. How do you add a legend to a plot?
9. Write code to plot two lines on the same graph:
python
CopyEdit
x = [0, 1, 2, 3]
y1 = [0, 1, 4, 9]
y2 = [0, 1, 2, 3]
10. How do you increase the size of a figure in matplotlib?
🔵 Advanced Level
11. How can you customize the line width and style in a line plot?
12. How do you save a plot to a file instead of displaying it?
13. Write a script to plot sin(x) and cos(x) on the same graph with appropriate labels and a
legend.
14. How can you change the tick marks on the x-axis?
15. How do you annotate a specific point on a plot?
🧠 Challenge Questions
16. Plot a line chart showing population growth over years using custom ticks and grid lines.
17. Create a line plot where the color of the line changes based on the y-value (e.g. using
LineCollection or segment coloring).
18. Plot multiple line charts on subplots (2x2 grid) using matplotlib.
19. How can you plot a line with markers only at every 5th data point?
20. Generate a line plot from a CSV file using pandas and matplotlib