matplotlib.axes.Axes.set_xticks, or matplotlib.axes.Axes.set_yticks for the y-axis, can be used to change the ticks and labels beginning with matplotlib 3.5.0. These are for the object oriented interface.
If using the pyplot state-based interface, use plt.xticks or plt.yticks, as shown in other answers.
In general terms, pass a list / array of numbers to the ticks parameter, and a list / array strings to the labels parameter.
In this case, the x-axis is comprised of continuous numeric values, so there are no set Text labels, as thoroughly explained in this answer. This is not the case when plots have discrete ticks (e.g. boxplot, barplot).
[Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, '')] is returned by ax.get_xticklabels()
[-0.25 0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. 2.25] is returned by ax.get_xticks()
type(ax.get_xticks()) is <class 'numpy.ndarray'>
type(ax.get_xticks()[0]) is <class 'numpy.float64'>
Since the OP is trying to replace a numeric label with a str, all of the values in the ndarray must be converted to str type, and the value to be changed can be updated.
Tested in python 3.10 and matplotlib 3.5.2
import numpy as np
import matplotlib.pyplot as plt
# create figure and axes
fig, ax = plt.subplots(figsize=(8, 6))
# plot data
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
# plot
ax.plot(t, s)
# get the xticks, which are the numeric location of the ticks
xticks = ax.get_xticks()
# get the xticks and convert the values in the array to str type
xticklabels = list(map(str, ax.get_xticks()))
# update the string to be changed
xticklabels[1] = 'Test'
# set the xticks and the labels
_ = ax.set_xticks(xticks, xticklabels)
注意,更改xticklabels时,x轴偏移量不会保留。但是,正确的值没有偏移量。
# create figure and axes
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 6), sharex=False)
# plot data
t = np.linspace(0, 1500000, 100)
s = t**2
# plot
ax1.plot(t, s)
ax2.plot(t, s)
# get the xticks, which are the numeric location of the ticks
xticks = ax2.get_xticks()
# get the xticks and convert the values in the array to str type
xticklabels = list(map(str, ax2.get_xticks()))
# update the string to be changed
xticklabels[1] = 'Test'
# set the xticks and the labels
_ = ax2.set_xticks(xticks, xticklabels, rotation=90)