![](/img/trans.png)
[英]Change bar order and legend order in plot (matplotlib/pandas)
[英]bar plot does not respect order of the legend text in matplotlib
只是注意到圖例文本與繪圖欄的順序不同。 我希望看到“香蕉”成為傳說中的第一名。 是否可以糾正這種行為? 謝謝
我的代碼是:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({"Apple" : [2,3,4,1], "Banana" : [4,2,1,2]})
ax = df.plot.barh()
ax.legend()
plt.show()
我的圖:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.