fix function to create bar chart with pyplot to handle legend better