Explanation of Solution
Function “xticks()”:
- • Function “xticks()” displays the customized tick mark labels along the X axis.
- • This function sets the X limits of the current location with the tick label.
Syntax:
The “xticks()” function has the below format.
#Customize the tick marks along the X axis
plt.xticks(locations, labels)
Explanation:
Here,
- • “xticks()” is the function that customizes the tick marks along the X axis.
- • The variables “locations” and “labels” are one-dimensional list that specifies the tick mark locations and its corresponding labels.
Example program:
The below example shows how to use the “xticks()” function in Python.
#Import the files
import matplotlib.pyplot as plt
#Function definition
def main():
#Define the left edges
leftedges=[0,10,20,30,40]
#Define the heights
heights=[500,800,645,700,900]
#Create a bar chart
plt.bar(leftedges, heights,5)
#Create X axis label
plt.xlabel('Year')
#Create Y axis label
plt.ylabel('Profit')
#Create X axis ticks
plt.xticks([0,10,20,30,40],
['2010','2011','2012','2013','2014'])
#Show the graph
plt.show()
#Call the function
main()
In the above code,
- • Define the function “main()”. Inside the function,
- ○ Create two lists to store the left edges and heights of all the bars.
- ○ Then create labels for the X and Y axes.
- ○ The function “xticks()” places the tick marks in the X axis at locations “0, 10, 20, 30,and 40” with the labels “2010, 2011, 2012, 2013, and 2014”, respectively.
Output:
Screenshot of the bar chart using the function “xticks()”
Function “yticks()”:
- • The function “yticks()” in Python enables the user to customize the tick marks labels along the Y axis.
- • This function sets the Y limits of the current location with the given tick label.
Syntax:
The “yticks()” function has the below format.
#Customize the tick marks along the Y axis
plt...
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with Python (4th Edition)
- 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