Se7eN
Se7eN

Reputation: 598

python seaborn.distplot incorrect legend

I'm getting incorrect legends when using different linestyles in seaborn.distplot

Here's my code:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

URL = "https://media.githubusercontent.com/media/WillKoehrsen/Data-Analysis/master/univariate_dist/data/formatted_flights.csv"
df = pd.read_csv(URL, index_col=0)
airlines = df['name'].unique().tolist()

LINE_STYLES = ['solid', 'dashed', 'dashdot', 'dotted']
plt.figure(figsize=(15,8))

plt.title('Histogram of Arrival Days', fontsize=18)
plt.xlabel('Delay (min)', fontsize=18)
plt.ylabel('Flights', fontsize=18)

for i, airline in enumerate(airlines):
  sns.distplot(df[df['name'] == airline]['arr_delay'], label=airline, bins=int(180/5), 
                    hist=False, kde_kws={'linewidth': 3, 'shade':True, 'linestyle':LINE_STYLES[i%4]})

The plot looks like this: enter image description here

The legend for Alaska Airlines should be -. (as in American Airline) but it is - (as in United Airline)

Upvotes: 0

Views: 1621

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339062

Ah I see. So the line is too thick to observe a difference between solid and dashdot. It would be correct if using e.g. 'linewidth': 1.

enter image description here

Alternatively you can create your own linestyle, e.g.

LINE_STYLES = ['solid', (0,(3,1)), (0,(4,2,1,2)), 'dotted']

enter image description here

Upvotes: 1

Related Questions