可以使用matplotlib库中的barh函数来绘制水平条形图,并将数据按照需要的顺序排序。示例代码如下:
import matplotlib.pyplot as plt import numpy as np
y = np.random.randint(1, 50, size=10) x = np.arange(10)
sorted_index = np.argsort(y)
plt.barh(x, y[sorted_index]) plt.yticks(x, sorted_index)
plt.show()
下一篇:按照y轴上的值进行排序