How to use Plot In Python
plot() method used to plot the graph between 2 data points. It takes 4 parameters those are 2 data points, marker, and marker-size.
Syntax: matplotlib.pyplot.plot(data1, data2, marker=’.’, markersize=constant)
Parameters:
- data1,data2- Variables that hold data.
- marker=’.’ – Indicates dot symbol to mark the datapoints.
- markersize- Represents size of marker
Example 1: Plot a graph using the plot method with standard marker size. (We do not need to mention the marker size in plot method)
Here we just plotted the graph using plot method with standard marker size.
Python3
# import necessary packages import matplotlib.pyplot as plt # data1&data2 data1 = [ 1 , 2 , 3 , 4 , 5 ] data2 = [ 1 , 2 , 1 , 2 , 1 ] # plot graph plt.plot(data1, data2, marker = "." ) plt.xlabel( 'x-axis' ) plt.ylabel( 'y-axis' ) |
Output:
Example 2: To adjust the size of marker in a plot use markersize parameter to plot method to adjust the marker size.
Here in this example, we adjusted the marker size to size 20 such that the maker size is increased from its standard size.
Python3
# import necessary packages import matplotlib.pyplot as plt # data1&data2 data1 = [ 1 , 2 , 3 , 4 , 5 ] data2 = [ 1 , 2 , 1 , 2 , 1 ] # plot graph plt.plot(data1, data2, marker = "." , markersize = 20 ) plt.xlabel( 'x-axis' ) plt.ylabel( 'y-axis' ) |
Output:
How to Adjust Marker Size in Matplotlib?
In this article, we are going to see how to adjust marker size in Matplotlib in Python.
We can adjust marker size in plots of matplotlib either by specifying the size of the marker in either plot method or scatter method while plotting the graph.