Page 125 - Informatics_Practices_Fliipbook_Class12
P. 125
• plt.title(): This function is used to set the title for the plot. It takes a string as an argument that
denotes the title of the graph.
The matplotlib library provides the function plt.savefig() for saving a graph. Name of the file (including
Ø
the file format) is provided as the input argument to the function plt.savefig(). By default, the figure
will be saved in the current working directory.
To enhance the readability of a graph, the plt module allows us to display a rectangular grid using the
Ø
method plt.grid().
The ticks on the x-axis mark the positions of the vertical lines of the grid. The ticks on the y-axis mark the
Ø
positions of the horizontal lines of the grid. The position of ticks is typically described using a sequence (using
a list, range(), etc.) provided as input to method xticks() and yticks().
A scatter plot comprises individual data points as markers on a two-dimensional graph. The scatter plot is
Ø
created using plt.scatter() function, where the x-axis represents expenses and the y-axis represents
revenue.
When multiple graphs are included in the same figure, this information is included by specifying the labels
Ø
while invoking the plt.plot() function for each graph.
We can utilise the subplot() function of matplotlib to create multiple subplots for separate functions
Ø
within a single figure. The syntax for subplot() is as follows:
subplot(rowNum, colNum, FigNum)
Bar graphs, often known as bar charts, are a common method for displaying categorical data. Matplotlib
Ø
method plt.bar(), can be used for plotting bar graphs which accept as input parameters a list of categories
that appear on the x-axis, and the associated counts that appear on the y-axis.
Histograms are popular data visualisation tools that offer a graphical depiction of a dataset's distribution.
Ø
Python includes function plt.hist() for producing and customising histograms.
Solved Exercise
A. Multiple Choice Questions
1. Which of the following Matplotlib function is used to create a line plot?
a. plt.line() b. plt.plot() c. plt.scatter() d. plt.bar()
2. Which of the following function can be used to add a label to the x-axis of a Matplotlib plot?
a. plt.xlabel() b. plt.ylabel() c. plt.title() d. plt.legend()
3. Which of the following plots is best suited to visualize the relationship between two continuous variables?
a. Pie Chart b. Bar graph c. Scatter plot d. Histogram
4. Which of the following plt.plot() functions can be used to create a solid red line with circular markers?
a. plt.plot(x, y, color='red', marker='circle')
b. plt.plot(x, y, style='r-', marker='o')
c. plt.plot(x, y, color='red', marker='o')
d. plt.plot(x, y, linestyle='-', marker='o', color='red')
5. Which of the following function is used to create multiple line plots on a single graph?
a. plt.multiple_lines() b. plt.plot_multiple()
c. plt.multiple() d. plt.plot()
Data Visualization 111

