我想做一個特殊的x-ticks標籤,我試圖在下面的照片中進行說明。 在matplotlib中設置x個刻度區域
你知道該怎麼做嗎?
編輯:我目前的代碼最低版本:
import matplotlib.pyplot as plt
xvalues = [ 0., 1., 1., 1., 1., 2., 2., 2., 2., 2.,
2., 3., 3., 3., 3., 4.]
yvalues = [ 1., 1., 1., 1., 1., 1., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0.]
tx = [0] * len(xvalues)
for i in range(len(xvalues)):
tx[i] = i
newxvalues = xvalues
seen = set()
newxvalues = [x if x not in seen and not seen.add(x) else '' for x in newxvalues ]
newxvalues[0] = ' '
plt.plot(tx, yvalues, color='g', linewidth=1.5)
plt.xlim([-1, len(xvalues)])
plt.xticks(tx, newxvalues, rotation="90")
plt.ylim(-0.03, 1.1)
plt.tick_params(axis='x', top='off', bottom='off')
plt.show()
EDIT2:我不需要花哨的括號,如果它簡化了問題。例如方括號也沒關係
也許你可以編輯清晰度的問題。 – Lucas