How to put legend outside the plot with pandas

I think you need to call plot before you add the calling legend.

import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
    'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}

d = pd.DataFrame(a).T
#print d

f = plt.figure()

plt.title('Title here!', color="black")
d.plot(kind='bar', ax=f.gca())
plt.legend(loc="center left", bbox_to_anchor=(1.0, 0.5))
plt.show()

—– Panda solution
If you are using pandas Dataframe.plot

dataframe_var.plot.bar().legend(loc="center left",bbox_to_anchor=(1.0, 0.5));

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)