Matplotlib
pyplot
Most of the Matplotlib utilities lies under the pyplot submodule, and are usually imported under the plt alias:
1 | import matplotlib.pyplot as plt |
Function
plot()
The plot() function is used to draw points in a diagram. This function takes two parameters for specifying points in the diagram.
Parameter1 is a array that define the range on x-axis.
Paramete21 is a array that define the range on y-axis.
By default, the plot() function draws a line from point to point.
point to point
Example
1 | import matplotlib.pyplot as plt |
So we draw a line from position(1,2) to (3,4)

To plot only the markers, you can use shortcut string notation parameter ‘o’
1 | plt.plot(x,y,'o') |

Multiple points
You can add more elements in the np.array(), so that we can define more points.
1 | x=np.array([1,5,7,10]) |
As we can see, we draw a line from position(1,1) to (5,10) then to (7,1) and to (10,10)

Scatter
With Pyplot, you can use the scatter() function to draw a scatter plot.
1 | import matplotlib.pyplot as plt |
Bars
With Pyplot, you can use the bar() function to draw bar graphs:
1 | import matplotlib.pyplot as plt |
Histogram
A histogram is a graph showing frequency distributions.
It is a graph showing the number of observations within each given interval.
In Matplotlib, we use the hist() function to create histograms.
1 | import matplotlib.pyplot as plt |
Pie Charts
You can use pie() function to draw pie charts.
1 | import matplotlib.pyplot as plt |
Add labels to the pie chart with the label parameter.
1 | mylabels = ["Apples", "Bananas", "Cherries", "Dates"] |
