擅长:python、mysql、java
<p>使用<code>ax.set_xticks</code>,您当前指定的记号位置与列表的顺序是不变的。要么传递<code>[0, 1, 2, 3, 4, 5]</code>,要么传递<code>[5, 4, 3, 2, 1, 0]</code>。这种区别不会在滴答声中被注意到。相反,您想要的是反转ticklabels,您应该这样做<code>set_xticklabels(xticks[::-1])</code>。有两种方法:</p>
<p><strong>方法1</strong></p>
<p>使用<code>plt.xticks</code>,其中第一个参数指定记号的位置,第二个参数指定相应的记号标签。具体来说,<code>xticks</code>将提供刻度位置,<code>xticks[::-1]</code>将用反转的ticklabels标记您的绘图。在</p>
<pre><code>xticks = range(n)
# plot the data
plt.figure()
ax = plt.subplot(111)
ax.bar(x, y)
plt.xticks(xticks, xticks[::-1])
</code></pre>
<p><strong>方法2</strong>使用<code>ax</code>在需要<code>set_xticklabels</code>的地方得到你想要的</p>
^{pr2}$
<p><a href="https://i.stack.imgur.com/EGWvR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EGWvR.png" alt="enter image description here"/></a></p>