Matplotlib (Class 12 Python)
– Matplotlib is a Python library used for data
visualization.
– Used to create plots, charts and graphs.
Why Use Matplotlib?
– Easy to create high quality graphs.
‑
– Supports many plot types.
– Widely used in Data Science.
Basic Syntax
– import matplotlib.pyplot as plt
– plt.plot(x, y)
– plt.show()
Types of Plots
– Line Plot
– Bar Chart
– Histogram
– Scatter Plot
– Pie Chart
Line Plot
– Used to show trends over time.
– Syntax: plt.plot(x, y)
Example: Line Plot
– import matplotlib.pyplot as plt
– x=[1,2,3,4]
– y=[10,20,15,30]
– plt.plot(x,y)
– plt.show()
Bar Chart
– Used to compare values across categories.
– Syntax: plt.bar(x, height)
Example: Bar Chart
– x=['A','B','C']
– y=[10,25,15]
– plt.bar(x,y)
Scatter Plot
– Shows relationship between two variables.
– Syntax: plt.scatter(x, y)
Histogram
– Represents distribution of data.
– Syntax: plt.hist(data)
Pie Chart
– Used to show proportion of categories.
– Syntax: plt.pie(values, labels=labels)
Adding Labels
– plt.xlabel('X-axis')
– plt.ylabel('Y-axis')
– plt.title('Graph Title')
Figure Size
– plt.figure(figsize=(6,4))
– Used to change graph dimensions.
Multiple Plots
– plt.subplot(rows, columns, plot_number)
Saving Graph
– plt.savefig('graph.png')
Styling
– color, linestyle, linewidth options available
Common Functions
– plt.grid()
– plt.legend()
– plt.xlim() / plt.ylim()
Real-Life Uses
– Data analysis
– Machine learning
– Business reporting
Summary
– Matplotlib is essential for visualization.
– Supports many chart types.
– Simple and powerful.
End
– Thank You!

CBSEMOSTIMPORMatplotlib_Class12_PPT.pptx