Here is a sample code:
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import math
x = np.arange(0, math.pi*2, 0.05)
fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
y = np.sin(x)
ax.plot(x, y, marker='s')
ax.set_xlabel('angle')
ax.set_title('sine')
#ax.set_xticklabels([" ",1,2,3,4,5," "]) # don't work
ax.set_yticks([-1,0,1])
plt.show()
It creates this Figure:
For the x-axis, I would like to amend the x-axis ticklabels to only show 1,2,3,4,5 while I would like to blank-out 0 and 6. I tried ax.set_xticklabels([" ",1,2,3,4,5," "])
but this did not work. I get this outcome instead:
and this warning msg:
Warning (from warnings module):
File "~/test.py", line 12
ax.set_xticklabels(["",1,2,3,4,5,""]) # don't work
UserWarning: FixedFormatter should only be used together with FixedLocator
How do I amend the x-axis ticklabels to only show 1,2,3,4,5?