4.3 Introduction of MATPLOTLIB
Introduction of MATPLOTLIB: -
- Matplotlib is a popular Python library used for creating visualizations, including plots and graphs.
- Though Matplotlib is mainly for plotting, it can also help in generating sample data for visualization using functions like numpy integration.
- Generating data allows you to simulate real-world data for testing and analysis.
- To use Matplotlib for plotting and data generation, we usually import:
Installing
MatPlotLib: -
- Matplotlib can be installed by using command py -m pip install matplotlib
Plotting with PYPLOT: -
- Matplotlib is a Python library for creating 2D plots and graphs.
- Pyplot is a submodule of Matplotlib that provides a Matlab-like interface for plotting.
- Using Pyplot, we can create line plots, scatter plots, bar charts, histograms, and more.
- To use Pyplot, we import
- Often, numpy is imported to generate or manage numeric data:
- Basic plotting can be as follows:
1. Creating a
Simple Line Plot: -
A line plot can be created using plt.plot( ):
plt.show( )
is used to display the plot.
We can Titles
and axis labels improve plot readability:
Example: -
Output: -
2. Creating
multiple Line Plots: -
We can plot
multiple lines on same axis
Example: -
Output: -
3. Creating
Plotting Line Graph: -
The line
graph is on e of the charts which shows the information as a series of the
line.
The graph is
plotted by the plot( ) function.
Example: -
Output: -