2021年1月23日星期六

Seaborne Linechart Style Causing Duplicate Legend Entries

I'm using seaborn to plot the results of some work using Benford's Law. The plot has two axes: a barplot representing the relative frequency of the digits in the input data, and a linechart representing the expected frequencies from Benford's Law.

As in this question, I used the style=True option so that I could control the style of my line. Unfortunately, this causes a duplicate entry in my legend, which I can't seem to remove. How can I correct the duplicate entry in my legend?

Current code:

def plot(inputdata, digits, y_col_actual, y_col_expected):        plt.rcParams['patch.force_edgecolor']=True        ax1 = sns.barplot(          data=inputdata,          x = digits,          y = y_col_actual,          color = '#B2E8C2',          label='Actual Data'          )      ax1.set(ylabel='Relative Frequency')        ax2 = sns.lineplot(          data=inputdata,          x = digits,          y = y_col_expected,          ax = ax1,          zorder = 5,          color = 'black',          style=True,          dashes=[(2,2)],          markers=True,          label='Benfords Law',          )            plt.show()  

And the resulting plot:

enter image description here

https://stackoverflow.com/questions/65866533/seaborne-linechart-style-causing-duplicate-legend-entries January 24, 2021 at 10:08AM

没有评论:

发表评论