Fix Python – Hide tick label values but keep axis labels

Question

Asked By – Luis Ramon Ramirez Rodriguez

I have this image:

plt.plot(sim_1['t'],sim_1['V'],'k')
plt.ylabel('V')
plt.xlabel('t')
plt.show()

enter image description here

I want to hide the numbers; if I use:

plt.axis('off')

…I get this image:

enter image description here

It also hide the labels, V and t. How can I keep the labels while hiding the values?

Now we will see solution for issue: Hide tick label values but keep axis labels


Answer

If you use the matplotlib object-oriented approach, this is a simple task using ax.set_xticklabels() and ax.set_yticklabels(). Here we can just set them to an empty list to remove any labels:

import matplotlib.pyplot as plt

# Create Figure and Axes instances
fig,ax = plt.subplots(1)

# Make your plot, set your axes labels
ax.plot(sim_1['t'],sim_1['V'],'k')
ax.set_ylabel('V')
ax.set_xlabel('t')

# Turn off tick labels
ax.set_yticklabels([])
ax.set_xticklabels([])

plt.show()

If you also want to remove the tick marks as well as the labels, you can use ax.set_xticks() and ax.set_yticks() and set those to an empty list as well:

ax.set_xticks([])
ax.set_yticks([])

This question is answered By – tmdavison

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0