- 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
Show tick labels when sharing an axis in Matplotlib
To show the tick labels when sharing an axis, we can just use the subplot() method with sharey argument. By default, y ticklabels could be visible.
Steps
Set the figure size and adjust the padding between and around the subplots.
Add a subplot to the current figure using subplot() method, where nrows=1, ncols=2 and index=1 for axis ax1.
Plot a line on the axis 1.
Add a subplot to the current figure, using subplot() method, where nrows=1, ncols=2 and index=2 for axis ax2.
Plot a line on the axis 2.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ax1 = plt.subplot(1, 2, 1) ax1.plot([1, 4, 9]) ax2 = plt.subplot(1, 2, 2, sharey=ax1) ax2.plot([1, 8, 27]) plt.show()
Output
- Related Articles
- Hide axis values but keep axis tick labels in matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to show tick labels on top of a matplotlib plot?
- Centering x-tick labels between tick marks in Matplotlib
- How to show minor tick labels on a log-scale with Matplotlib?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- Change grid interval and specify tick labels in Matplotlib
- How to rotate tick labels in a subplot in Matplotlib?
- Getting empty tick labels before showing a plot in Matplotlib
- How to rotate X-axis tick labels in Pandas bar plot?
- How to decrease the density of tick labels in subplots in Matplotlib?
- Increasing the space for X-axis labels in Matplotlib
- How do I change the axis tick font in a Matplotlib plot when rendering using LaTeX?
- Turn off the left/bottom axis tick marks in Matplotlib

Advertisements