Reputation: 598
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 legend for Alaska Airlines should be -. (as in American Airline) but it is - (as in United Airline)
Upvotes: 0
Views: 1621
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
.
Alternatively you can create your own linestyle, e.g.
LINE_STYLES = ['solid', (0,(3,1)), (0,(4,2,1,2)), 'dotted']
Upvotes: 1