【发布时间】:2019-11-14 12:56:45
【问题描述】:
我有一个带有辅助 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()
一组条出现在图例的后面,一组出现在图例的前面。下面的链接转到显示问题的图像。谢谢!
【问题讨论】:
标签: python pandas matplotlib plot jupyter-notebook