Page 131 - Informatics_Practices_Fliipbook_Class12
P. 131
OR
import matplotlib.pyplot as plt
sales=[450,300,500,650]
qtr=["QTR1","QTR2","QTR3","QTR4"]
plt.bar(qtr,sales)
plt.xlabel("Quarter")
plt.ylabel("Sales")
plt.title("Sales each quarter")
plt.show()
NCERT Exercise Solutions
1. What is the purpose of the Matplotlib library?
Ans. Refer to 3.1.2 Displaying a Line Joining the Points, Saving Figure
2. What are some of the major components of any graphs or plot?
Ans. The following are some of the main components of any graph or plot:
Figure: The overall window or page that everything is drawn on.
Axis: The number line along the edges of the plot.
Title: A description or label for the plot.
Labels: Descriptions for the x and y-axis.
Legend: A box describing the elements of the plot.
Grid: Horizontal and vertical lines that aid in reading values from the plot.
Markers/lines: Symbols or lines that represent the data points or trends.
Color and style: Attributes that determine the appearance of markers, lines, and other elements.
Ticks: The marks on the axis indicating specific points.
3. Name the function which is used to save the plot.
Ans. Refer to 3.1.2 Displaying a Line Joining the Points, Saving Figure
4. Write short notes on different customisation options available with any plot.
Ans. 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.
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.
Data Visualization 117

