use*_*614 2 python plot matplotlib
如何绘制条形图,其中x轴值从最高到最低按降序排列?
例:
出于示例目的,我的绘图如下所示:

我需要图形对分别绘制星期一(最高值),星期三,星期二(最小值)的位置进行排序
这是我到目前为止的内容:
x_axis = ['a','b','c'...'z']
y_axis = [#...#...#] number values for each letter in xaxis
def barplot(x_axis, y_axis): #x and y axis defined in another function
x_label_pos = range(len(y_axis))
plot.bar(x_label_pos, y_axis)
plot.yticks(range(0, int(max(y_axis) + 2), 2))
plot.xticks(x_axis)
Run Code Online (Sandbox Code Playgroud)
# grab a reference to the current axes
ax = plt.gca()
# set the xlimits to be the reverse of the current xlimits
ax.set_xlim(ax.get_xlim()[::-1])
# call `draw` to re-render the graph
plt.draw()
Run Code Online (Sandbox Code Playgroud)
matplotlib 如果您将x限制设置为左侧值大于右侧值(与y轴相同),则将“执行正确的操作”。