How to hide axis of plot in Matplotlib

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.

  • To hide the axis of a plot:
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)
  • To hide only the ticks of a plot:
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([])
  • To hide only the labels of the ticks of a plot:
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

Advertisements

One thought on “How to hide axis of plot in Matplotlib”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s