Skip to content
Advertisement

Hide tick label values but keep axis labels

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?

Advertisement

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([])
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement