I can remove the ticks with
ax.set_xticks([]) ax.set_yticks([])
but this removes the labels as well. Any way I can plot the tick labels but not the ticks and the spine
By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis. In the above example, we use plt. xticks([]) method to invisible both the ticks and labels on the x-axis and set the ticks empty.
To fix the position of ticks, use set_xticks() function. To set string labels at x-axis tick labels, use set_xticklabels() function.
To hide or remove X-axis labels, use set(xlabel=None). To display the figure, use show() method.
You can set the tick length to 0 using tick_params
(http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.tick_params):
fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1],[1]) ax.tick_params(axis=u'both', which=u'both',length=0) plt.show()
Thanks for your answers @julien-spronck and @cmidi.
As a note, I had to use both methods to make it work:
import numpy as np import matplotlib.pyplot as plt fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(11, 3)) data = np.random.random((4, 4)) ax1.imshow(data) ax1.set(title='Bad', ylabel='$A_y$') # plt.setp(ax1.get_xticklabels(), visible=False) # plt.setp(ax1.get_yticklabels(), visible=False) ax1.tick_params(axis='both', which='both', length=0) ax2.imshow(data) ax2.set(title='Somewhat OK', ylabel='$B_y$') plt.setp(ax2.get_xticklabels(), visible=False) plt.setp(ax2.get_yticklabels(), visible=False) # ax2.tick_params(axis='both', which='both', length=0) ax3.imshow(data) ax3.set(title='Nice', ylabel='$C_y$') plt.setp(ax3.get_xticklabels(), visible=False) plt.setp(ax3.get_yticklabels(), visible=False) ax3.tick_params(axis='both', which='both', length=0) plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With