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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-03-14 11:00:00 +0000
Seen: 10 times
Last updated: Jul 17 '21
What is the process for reading a .txt file using VBA and inserting a string into a label?
How can the header label be made dynamic in react-table?
How can the width of a label in React Native Picker be adjusted?
How can a VS Code Snippet be modified to convert a label to lowercase using regex?
What is the method to include a count label in a ggplot2 histogram that employs breaks?