How to add legend on Seaborn facetgrid bar plot

后端 未结 2 1282
情书的邮戳
情书的邮戳 2021-01-02 02:31

I have the following code:

import numpy as np
import pandas as pd
import matplotlib
matplotlib.use(\'Agg\')
import matplotlib.pyplot as plt
matplotlib.style.         


        
2条回答
  •  执念已碎
    2021-01-02 02:57

    When the legend doesn't work out you can always make your own easily like this:

    import matplotlib
    
    name_to_color = {
        'Expected':   'green',
        'Provided':   'red',
        'Difference': 'blue',
    }
    
    patches = [matplotlib.patches.Patch(color=v, label=k) for k,v in name_to_color.items()]
    matplotlib.pyplot.legend(handles=patches)
    

提交回复
热议问题