在本例中:
import matplotlib.pyplot as plt
colors = ['white', 'orange', 'green', 'purple']
rates = ['5','5','4','3']
plt.bar(colors, rates)图中的条形按字母顺序排列。
如何使它们以与代码中相同的顺序显示(从最高到最低)?
发布于 2017-12-09 17:52:45
使用值0,1,2,3,4,...作为x,并将colors与tick_label=分配
import matplotlib.pyplot as plt
colors = ['white', 'orange', 'green', 'purple']
rates = ['5','5','4','3']
plt.bar(range(len(colors)), rates, tick_label=colors)
plt.show()https://stackoverflow.com/questions/47731289
复制相似问题