1 | initial version |
One way to do this is to set the tick labels to an empty string using the set_ticklabels()
method and then set the axis label using the set_label()
method.
Here's an example:
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
x = np.arange(0, 10, 0.1)
y = np.sin(x)
# Create the plot
fig, ax = plt.subplots()
ax.plot(x, y)
# Hide tick labels but retain the axis label
ax.set_xticklabels(['']*len(ax.get_xticks())) # hide x-axis tick labels
ax.set_yticklabels(['']*len(ax.get_yticks())) # hide y-axis tick labels
ax.set_xlabel('x-axis label')
ax.set_ylabel('y-axis label')
# Show the plot
plt.show()
This code will show the plot with axis labels but without tick labels. The set_xticklabels()
and set_yticklabels()
methods set the tick labels to an empty string using a list with the same length as the number of ticks.