

Sudipta Deb
Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect
Matplotlib.Pyplot is a compilation of utilities that enables matplotlib to operate similarly to MATLAB. Each pyplot function modifies a figure: for instance, it may generate a figure, establish a plotting area within a figure, plot lines in a plotting region, or embellish the plot with labels, among other actions.
In matplotlib.pyplot, various states are maintained across function calls, allowing it to monitor elements such as the current figure and plotting area, with plotting functions directed to the current Axes (note that "Axes" with an uppercase 'A' refers to the Axes concept, a fundamental component of a figure, rather than merely the plural of axis).
The form you have selected does not exist.
Sample Code
I normally put all my codes in my personal Github repository, so that I can easily share with others. Here is the Github Code Repo where you can find the code samples used in this blog post.
Create A Simple Plot
The most basic example is the plot() method to represent values as x,y coordinates in a data visualization. In this instance, plot() requires two parameters to define plot coordinates:
- Parameter for an array of X-axis coordinates.
- Parameter for an array of Y-axis coordinates.
A line extending from the coordinates (3, 1) to (10, 15) is represented by generating two arrays: (3, 10) and (1, 15).


Customize It With Marker & LineStyle
Marker and Linestyle are matplotlib keywords that can be used to customize the appearance of data in a plot without modifying data values.
- Marker is an argument used to label each data value in a plot with a ‘marker‘.
- Linestyle is an argument used to customize the appearance of lines between data values, or else remove them altogether.
In this example, each data value is labeled with the letter “X”, and given a dashed linestyle “--”


Scatterplot
Scatterplot is used to display data values as a collection of x,y coordinates represented by dots. In the below example, 2 arrays that represents the x and y coordinates are plotted using the Scatterplot.


Multiple Data Sets in One Plot
We can plot multiple data sets in one plot like below -


Subplots
We can use the Subplot to visualize more complex figures that contain more than one plat. In the below example, multiple axes are enclosed in one figure and displayed in subplots.


Final Thoughts
In summary, the matplotlib.pyplot.plot() method in Python is an essential instrument for generating diverse 2D charts, such as line plots and scatter plots. Its adaptability enables users to tailor plots by designating data points, line types, markers, and colors. The function offers versatility in plot layout and data management with optional parameters like 'fmt' and 'data.' Moreover, the provided Line2D objects facilitate additional editing and analysis of the plotted data. Matplotlib’s plot() function is an essential element in data visualization, providing an accessible interface for generating informative and aesthetically pleasing graphs in Python.
Disclaimer
This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.



0 Comments