Page 204 - Robotics and AI class 10
P. 204
The pyplot module of Matplotlib has built in methods which help in designing a graph with all features. Few
of the functions are explained below:
• The plot(x,y,marker) function is used to create a box-like figure where the actual graph is plotted. To plot
x axis versus y axis , we write plt.plot(x,y). By default it plots a line graph plt.plot(kind='line')
will make a line graph. We can have the following values of the kind parameter to change the type of the graph
needed to make.
kind can be:
Kind= Plot type
line Line plot (default)
bar Vertical bar plot
barh Horizontal bar plot
hist Histogram
box Boxplot
area Area plot
pie Pie plot
scatter Scatter plot
• The scatter(x, y) function will plot a scatter graph
• The show() function will display the figure created.
• The savefig(filename) function can be used to save the figure in your computer.
• The xlabel(Text) function is used to give label to x axis
• The ylabel(Text) function is used to give label to y axis
• The title(Text) function is used to give title to a graph created.
• The grid(True)function will add a grid to the graph created. Default is True. If you want grid on x-axis the the
function will be: grid(axis = 'x')and for y axis grid(axis = 'y')
• The xticks(values) function will mark the ticks/points on the x axis
• The yticks(values) function will mark the ticks/points on the y axis
Markers
Markers are the points on the graph that represent a data value on a line or scatter chart. Few of the Markers for
the graph are listed below:
Marker Symbol Descriptions Marker Symbol Description
"." Point "8" octagon
"," Pixel "s" square
"o" Circle "p" pentagon
"v" triangle_down "P" plus (filled)
"^" triangle_up "*" star
"<" triangle_left "h" hexagon1
">" triangle_right "H" hexagon2
"1" tri_down "+" plus
"2" tri_up "x" x
"3" tri_left "X" x (filled)
"4" tri_right "D" diamond
202 Touchpad Robotics & Artificial Intelligence-X

