I went through the following link before posting the question.
Get legend as a separate picture in Matplotlib
I am unable to replicate the provided solution for my example.
Here is my dataframe and the code. I want to save legend as a separate image.
df=pd.DataFrame(index=['A','B','C','D'], columns=['Values'])
df['Values'] = [0.45,0.28,0.21,0.3]
fig=plt.figure(figsize=(8,8))
ax1 = plt.subplot(121, aspect='equal')
df['Values'].dropna().plot(kind='pie', autopct='%1.0f%%', startangle=220, labels=None,
colors=['#002c4b','#392e2c','#92847a','#ccc2bb','#6b879d'])
patches, labels = ax1.get_legend_handles_labels()
pp = ax1.legend(patches, labels=df.index, loc='center right', bbox_to_anchor=(0, 0.5),
fontsize=8, frameon=False, labelspacing=4)
ax1.axis('off')
plt.ylabel('')
img_name = 'unit1.png'
plt.savefig(img_name,bbox_inches='tight', dpi = 300)
plt.close(fig)
Please suggest the way forward.