Concept explainers
<PROGRAM-DESCRIPTION-ANSWER>
The functions “xlabel()” and “ylabel()” are used to create labels to the axes in the graph.
</PROGRAM-DESCRIPTION-ANSWER>
Explanation of Solution
Function “xlabel()”:
- • The “xlabel()” function creates a label to the X axis.
- • This function gives a meaningful name to the X axis, so that, the information represented by the X axis will be understood clearly.
- • This function “xlabel()” takes a string as its input parameters.
Syntax:
The “xlabel()” function has the below format.
#Add label to X axis
plt.xlabel(label1)
Explanation:
Here,
- • “xlabel()” is the function that produces a label to the X axis.
- • The variable “label1” is a string that is going to name the X axis.
Example program:
The below example shows how to use the “xlabel()” function in Python,
#Import the files
import matplotlib.pyplot as plt
#Create a list to have the X coordinates of data points
xcoord = [1, 2, 3, 4]
#Create a list to have the Y coordinates of data points
ycoord = [2, 4, 6, 8]
#Call the function
plt.plot(xcoord, ycoord)
#Add label to the X axis
plt.xlabel('X axis')
#Show the graph
plt.show()
Sample Output:
Screenshot of the graph
In the above code,
- • The list “xcoord” represents the X coordinates of all the data points.
- • The list “ycoord” represents the Y coordinates of all the data points.
- • Then, the lists “xcoord” and “ycoord” are passed as input parameters to the “plot()” function to create a line graph.
- • The function “xlabel()” is called to assign the label “X axis” to the X axis.
- • Then, the graph is shown using “show()” function.
Function “ylabel()”:
- • The label to the Y axis is created by the function “ylabel()” ...
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with Python (4th Edition)
- 4- The-enables you to add plots to an existing graph.arrow_forwardConsider the line from (5, 5) to (13, 9).Use the Bresenham’s line drawing algorithm to draw this line. You are expected to find out all the pixels of the line and draw it on a graph paperarrow_forward7- A student has created a plot of y(t)=t^2. He needs to show another graph of z(t)=t^3 in the same plot. But every time he hits the plot() function- MATLAB generates a plot of z(t) vs t but on a different window. What is the error? O It is not possible to plot multiple plots O He is not using the line function Maybe he is using polar() instead of plot() O He is not using the hold functionarrow_forward
- 2. Use the following description of an undirected graph and draw the graph: v(Graph1) = { A, B, C, D} E(Graph1) = { (A,B), (A,D), (B,C), (B,D) }arrow_forwardComputer engineering quesstion Brian is a great mathematician. He recently managed to enter in world’s top 10 mathematician. His parents wanted to appreciate him and present him a Directed Acyclic Graph. He'd like to customize his graph. He wanted to add as many edges as possible in order to still have a DAG. Please, help Brian to write a python code, to find the maximum number of edges he can add to his graph without obtaining any cycle.Test your code on the following test case:3010000100Output:40 42 4arrow_forwardAdditional Topics: Hamiltonian Paths and Cycles A Hamiltonian path in a directed graph is a path that visits every vertex in the graph exactly once. A Hamiltonian cycle in a directed graph is a cycle that visits every vertex in the graph exactly once (except for the vertex at the beginning and end of the cycle). For example, in the following directed graph, 1,3,4,2 is a Hamiltonian path and 1,3,4,2, 1 is a Hamiltonian cycle. 2 3 4 7. Given the following directed graphs: 田街 G1 Answer the following questions: G2 Is there a Hamiltonian path in the graph? If so, find one. • Is there a Hamiltonian cycle in the graph? If so, find one. G3arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education