Page 124 - Informatics_Practices_Fliipbook_Class12
P. 124
Fig 3.21: Histogram showing frequency distribution of CGPA of students
Let's Summarise
Ø To plot the point(x,y), invoke the plot() method of pyplot plt module as follows: plt.plot(x, y,
format_string)
Method plt.plot() of module matplotlib.pyplot can be used for creating a plot. The first argument
Ø
represents the x-coordinate of the point, the second argument represents the y-coordinate, and the following
string specifies the style.
Matplotlib provides the plt.show() method to render the plot on the screen.
Ø
Ø We can also customize the points and line plot by setting the following parameters while invoking the plt.
plot() method:
• x: The x-coordinate or array of x-coordinates for the point(s) to be plotted.
• y: The y-coordinate or array of y-coordinates for the point(s) to be plotted. It should correspond to the
x-coordinates and have the same length.
• marker: Specifies the marker style for the point(s). The default marker is 'o', representing a circular
marker.
• markersize: Sets the size of the marker(s). The default size is 6.
• linestyle: Determines the line style connecting the point(s). The default linestyle is '-', representing a
solid line.
• color: Specifies the color of the marker(s) and line(s). The default color is 'blue'.
• linewidth: Sets the width of the line. The default linewidth is 1.0.
linestyle:
• markeredgecolor: Sets the color of the marker edges. The default color is 'blue'.
• markerfacecolor: Sets the color of the marker faces. The default color is 'blue'.
• markeredgewidth: Sets the width of the marker edges. The default linewidth is 1.0.
To name the axes and assign a title to a graph, the Matplotlib offers the following methods:
Ø
• plt.xlabel(): This function is used to set the label for the x-axis of the plot. It accepts a string as an
argument that denotes the label for the x-axis.
• plt.ylabel(): This function is used to set the label for the y-axis of the plot. It accepts a string as an
argument. that denotes the label for the y-axis.
110 Touchpad Informatics Practices-XII

