I have this image:
plt.plot(sim_1['t'],sim_1['V'],'k')
plt.ylabel('V')
plt.xlabel('t')
plt.show()
I want to hide the numbers; if I use:
plt.axis('off')
...I get this image:
It also hide the labels, V
and t
. How can I keep the labels while hiding the values?
This question is related to
python
matplotlib
If you use the matplotlib object-oriented approach, this is a simple task using ax.set_xticklabels()
and ax.set_yticklabels()
:
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()
This works great. Just paste this before plt.show()
:
plt.gca().axes.get_yaxis().set_visible(False)
Boom.
to remove tickmarks entirely use:
ax.set_yticks([])
ax.set_xticks([])
otherwise ax.set_yticklabels([])
and ax.set_xticklabels([])
will keep tickmarks.
Without a subplots
, you can universally remove the ticks like this:
plt.xticks([])
plt.yticks([])
Not sure this is the best way, but you can certainly replace the tick labels like this:
import matplotlib.pyplot as plt
x = range(10)
y = range(10)
plt.plot(x,y)
plt.xticks(x," ")
plt.show()
In Python 3.4 this generates a simple line plot with no tick labels on the x-axis. A simple example is here: http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html
This related question also has some better suggestions: Hiding axis text in matplotlib plots
I'm new to python. Your mileage may vary in earlier versions. Maybe others can help?
Source: Stackoverflow.com