Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to hide the Y-axis tick labels on a chart in Python Plotly?
Plotly is an open-source Python plotting library for creating interactive charts and visualizations. One common customization is hiding Y-axis tick labels to create cleaner charts or when the exact values are not needed.
In this tutorial, we will explore different methods to hide Y-axis tick labels using Plotly's graph_objects module and layout properties.
Method 1: Using showticklabels Property
The simplest approach is to set the showticklabels property to False in the Y-axis layout ?
import plotly.graph_objects as go
# Create a bar chart with hidden Y-axis tick labels
fig = go.Figure(
data=[go.Bar(y=[10, 20, 30, 40])],
layout={
'yaxis': {'showticklabels': False}
}
)
fig.update_layout(title="Hidden Y-axis Tick Labels")
fig.show()
Method 2: Using visible Property
You can also hide the entire Y-axis including tick labels by setting visible to False ?
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(y=[10, 20, 30, 40])],
layout={
'yaxis': {'visible': False}
}
)
fig.update_layout(title="Hidden Y-axis")
fig.show()
Complete Example with Customization
Here's a comprehensive example that hides Y-axis tick labels while keeping the axis line and customizing other properties ?
import plotly.graph_objects as go
fig = go.Figure(
data=[go.Bar(y=[10, 20, 30, 40])],
layout={
'xaxis': {
'title': 'Categories',
'visible': True,
'showticklabels': True
},
'yaxis': {
'title': 'Values',
'visible': True,
'showticklabels': False
},
'margin': dict(
l=50, # left
r=20, # right
t=50, # top
b=40 # bottom
)
}
)
fig.update_layout(
title="Bar Chart with Hidden Y-axis Tick Labels",
width=600,
height=400
)
fig.show()
Comparison
| Property | Effect | Best For |
|---|---|---|
showticklabels: False |
Hides only tick labels | Keep axis line visible |
visible: False |
Hides entire Y-axis | Minimal chart appearance |
Conclusion
Use showticklabels: False to hide Y-axis tick labels while keeping the axis visible. Use visible: False to hide the entire Y-axis for cleaner visualizations.
