- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to show tick labels on top of a matplotlib plot?
To show tick labels on top of a matplotlib plot, we can use the set_tick_params() method with labeltop=True.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots.
- Show the tick labels at the top of the plot. Use set_tick_parama() with labeltop=True.
- Hide the tick labels of the bottom axis of plot. Use set_tick_parama() with labeltop=False.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create subplots fig, ax = plt.subplots(1, 1) # Show the tick labels ax.xaxis.set_tick_params(labeltop=True) # Hide the tick labels ax.xaxis.set_tick_params(labelbottom=False) plt.show()
Output
It will produce the following output
- Related Articles
- How to show minor tick labels on a log-scale with Matplotlib?
- Getting empty tick labels before showing a plot in Matplotlib
- Show tick labels when sharing an axis in Matplotlib
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to rotate tick labels in a subplot in Matplotlib?
- How to plot additional points on the top of a scatter plot in Matplotlib?
- Centering x-tick labels between tick marks in Matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How to decrease the density of tick labels in subplots in Matplotlib?
- How to rotate X-axis tick labels in Pandas bar plot?
- How to increase/reduce the fontsize of X and Y tick labels in Matplotlib?
- How to plot a Bar Chart with multiple labels in Matplotlib?
- How to create a plot with tick marks between X-axis labels in base R?
- Change grid interval and specify tick labels in Matplotlib

Advertisements