我有一个带有辅助 y 轴的 pandas DataFrame,我需要一个条形图,条形图前面有图例。目前,图例前面有一组酒吧。如果可以的话,我还想把图例放在左下角。任何想法表示赞赏!
我尝试设置 legend=false 并添加自定义图例,但它有同样的问题。我已尝试对列进行重新排序,但无法在图表上为此清理空间。
import pandas as pd
import matplotlib.pyplot as plt
df_y = pd.DataFrame([['jade',12,800],['lime',12,801],['leaf',12,802],
['puke',12,800]], columns=['Territory','Cuisines','Restaurants'])
df_y.set_index('Territory', inplace=True)
plt.figure()
ax=df_y.plot(kind='bar', secondary_y=['Restaurants'])
ax.set_ylabel('Cuisines')
ax.right_ax.set_ylabel('Restaurants')
plt.show()
一组条形出现在图例后面,一组条形出现在图例前面。下面的链接指向显示问题的图像。谢谢你!