Code Yarns ‍👨‍💻

How to hide axis of plot in Matplotlib

(First posted on: 2015-06-29 12:21:00+00:00)

For most types of plots drawn by Matplotlib, the ticks and labels along both X and Y axis is drawn too. To hide the ticks, labels or axis, we need to get the axes of the currently generated plot and change its properties.

import matplotlib.pyplot as mplot

# After creating plot ...

cur_axes = mplot.gca()
cur_axes.axes.get_xaxis().set_visible(False)
cur_axes.axes.get_yaxis().set_visible(False)
import matplotlib.pyplot as mplot

# After creating plot ...

cur_axes = mplot.gca()
cur_axes.axes.get_xaxis().set_ticks([])
cur_axes.axes.get_yaxis().set_ticks([])
import matplotlib.pyplot as mplot

# After creating plot ...

cur_axes = mplot.gca()
cur_axes.axes.get_xaxis().set_ticklabels([])
cur_axes.axes.get_yaxis().set_ticklabels([])

Tried with: Matplotlib 1.3.1 and Ubuntu 14.04