matplotlib bar plot add legend from categories dataframe column
问题 I try to add the legend which should, according to my example, output: a red square with the word fruit and a green square with the word veggie. I tried several things (the example below is just 1 of the many trials), but I can't get it work. Can someone tell me how to solve this problem? import pandas as pd from matplotlib import pyplot as plt data = [['apple', 'fruit', 10], ['nanaba', 'fruit', 15], ['salat','veggie', 144]] data = pd.DataFrame(data, columns = ['Object', 'Type', 'Value'])