Page 157 - Touhpad Ai
P. 157
Matplotlib
Matplotlib is one of the most popular and powerful libraries in Python for creating charts. It is highly flexible and allows
full control over the appearance of graphs. It allows users to create almost any type of chart, ranging from simple
plots to highly customised graphs. It gives full control over elements like colours, labels, titles, grid lines, and markers,
making it suitable for both beginners and professionals.
To install the Matplotlib library, use one of the following commands in the terminal or command prompt:
pip install matplotlib
or
python -m pip install -U matplotlib
While writing a Python program, we import the pyplot module from the Matplotlib library using the following command:
import matplotlib.pyplot as plt
The pyplot submodule provides a MATLAB-like interface, which includes simple functions to create and manage basic
plots.
Some of the common functions of Matplotlib library with their descriptions is given below:
Function Name Description
title( ) Adds title to the chart/graph
xlabel( ) Gives label for x-axis
ylabel( ) Gives label for y-axis
xlim( ) Gives the value limit for x-axis
ylim( ) Gives the value limit for y-axis
xticks( ) Places the tick marks on the x-axis
yticks( ) Places the tick marks on the y-axis
show( ) Displays the graph on the screen
savefig("address") Saves the graph to the given address
figure(figsize = value in Sets the size of the plot where the graph is drawn. Values should be supplied
tuple format) in tuple format to the figsize attribute, which is passed as an argument.
Seaborn
Seaborn is built on top of Matplotlib and makes creating attractive and statistical charts easier. It simplifies the process
of adding styles, colours, and advanced plots. It makes it easier to produce attractive visualizations, such as heatmaps,
box plots, violin plots, and pair plots, which are particularly useful for analysing relationships between multiple variables.
To install the Seaborn library, use one of the following commands in the terminal or command prompt:
pip install seaborn
or
python -m pip install -U seaborn
While writing a Python program, we import the seaborn module using the following command:
import seaborn as sns
You can combine with Matplotlib to show the plot using the following command:
import matplotlib.pyplot as plt
plt.show()
Data Visualization 155

