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:
question from:
https://stackoverflow.com/questions/65866533/seaborne-linechart-style-causing-duplicate-legend-entries 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…