python seaborn.distplot不正确的图例

时间:2019-02-10 09:19:37

标签: python matplotlib seaborn density-plot

在seaborn.distplot中使用不同的线型时,我得到的图例不正确

这是我的代码:

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]})

情节看起来像这样: enter image description here

阿拉斯加航空公司的传说应该是-。 (如美国航空公司),但--(如美国航空公司)

1 个答案:

答案 0 :(得分:1)

我明白了。因此,该线太粗,无法观察到soliddashdot之间的差异。如果使用例如'linewidth': 1

enter image description here

或者,您可以创建自己的线型,例如

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

enter image description here