How to hide axes but keep axis-labels in 3D Plot with Matplotlib?

When working with 3D plots in Matplotlib, you might want to hide the axis lines and grids while keeping the axis labels visible for clarity. This creates a cleaner visualization that focuses on the data while maintaining orientation information.

Understanding the Approach

To hide axes but keep axis labels in a 3D plot, we need to:

  • Set the axis pane colors to transparent
  • Make axis lines invisible by setting their color to transparent
  • Remove tick marks while preserving axis labels
  • Configure the plot appearance for better visualization

Complete Example

Here's how to create a 3D bar plot with hidden axes but visible labels ?

import numpy as np
import matplotlib.pyplot as plt

# Set figure size and layout
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# Create figure and 3D subplot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Create sample data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [5, 6, 7, 8, 2, 5, 6, 3, 7, 2]
z = np.zeros(10)

dx = np.ones(10)
dy = np.ones(10)
dz = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Create 3D bar plot
ax.bar3d(x, y, z, dx, dy, dz, color="green")

# Hide axes by making them transparent
color_tuple = (1.0, 1.0, 1.0, 0.0)  # White with 0 alpha (transparent)

# Set pane colors to transparent
ax.w_xaxis.set_pane_color(color_tuple)
ax.w_yaxis.set_pane_color(color_tuple)
ax.w_zaxis.set_pane_color(color_tuple)

# Set axis line colors to transparent
ax.w_xaxis.line.set_color(color_tuple)
ax.w_yaxis.line.set_color(color_tuple)
ax.w_zaxis.line.set_color(color_tuple)

# Remove tick marks
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

# Keep axis labels visible
ax.set_xlabel('X-Axis')
ax.set_ylabel('Y-Axis')
ax.set_zlabel('Z-Axis')

plt.show()

Key Components Explained

Color Tuple Configuration

The color_tuple = (1.0, 1.0, 1.0, 0.0) represents RGBA values where the last value (0.0) makes elements completely transparent.

Axis Pane Settings

The set_pane_color() method hides the background planes of each axis, while line.set_color() hides the axis lines themselves.

Tick Configuration

Setting empty lists with set_xticks([]) removes tick marks while preserving the ability to display axis labels.

Alternative Approach

You can also use different transparency levels for a subtle effect ?

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')

# Sample data
x = np.random.randint(1, 10, 8)
y = np.random.randint(1, 10, 8)
z = np.zeros(8)
dx = dy = 0.8
dz = np.random.randint(1, 8, 8)

ax.bar3d(x, y, z, dx, dy, dz, color='skyblue', alpha=0.8)

# Semi-transparent axes for subtle effect
semi_transparent = (1.0, 1.0, 1.0, 0.1)

ax.w_xaxis.set_pane_color(semi_transparent)
ax.w_yaxis.set_pane_color(semi_transparent)
ax.w_zaxis.set_pane_color(semi_transparent)

# Remove ticks but keep labels
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

ax.set_xlabel('Categories')
ax.set_ylabel('Groups')
ax.set_zlabel('Values')

plt.show()

Conclusion

By setting axis pane and line colors to transparent and removing tick marks, you can create clean 3D visualizations that focus on the data while maintaining essential orientation information through axis labels.

Updated on: 2026-03-25T21:34:02+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements