Modify A Specific X-axis Tick Label In Python
I am an undergrad newbie to the Python pyplot. What I want to do is to plot a function against a sequence, for example, x = [1,2,3,4,5]. The pyplot.plot function naturally gives a
Solution 1:
This is how you do it:
from matplotlib import pyplot as plt
x = [1,2,3,4,5]
y = [1,2,0,2,1]
plt.clf()
plt.plot(x,y,'o-')
ax = plt.gca() # grab the current axis
ax.set_xticks([1,2,3]) # choose which x locations to have ticks
ax.set_xticklabels([1,"key point",2]) # set the labels to display at those ticks
By omitting 4 and 5 from your xtick list, they won't be shown.
Post a Comment for "Modify A Specific X-axis Tick Label In Python"