Add Legend to Seaborn point plot

后端 未结 3 1104
孤街浪徒
孤街浪徒 2020-12-09 02:50

I am plotting multiple dataframes as point plot using seaborn. Also I am plotting all the dataframes on the same axis.

How wou

3条回答
  •  借酒劲吻你
    2020-12-09 03:16

    I tried using Adam B's answer, however, it didn't work for me. Instead, I found the following workaround for adding legends to pointplots.

    import matplotlib.patches as mpatches
    red_patch = mpatches.Patch(color='#bb3f3f', label='Label1')
    black_patch = mpatches.Patch(color='#000000', label='Label2')
    

    In the pointplots, the color can be specified as mentioned in previous answers. Once these patches corresponding to the different plots are set up,

    plt.legend(handles=[red_patch, black_patch])
    

    And the legend ought to appear in the pointplot.

提交回复
热议问题