简体   繁体   English

python seaborn.distplot不正确的图例

[英]python seaborn.distplot incorrect legend

I'm getting incorrect legends when using different linestyles in seaborn.distplot 在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: 情节看起来像这样: 在此处输入图片说明

The legend for Alaska Airlines should be -. 阿拉斯加航空的传说应该是-。 (as in American Airline) but it is - (as in United Airline) (如美国航空),但--(如美国航空)

Ah I see. 啊,我明白了。 So the line is too thick to observe a difference between solid and dashdot . 因此,该线太粗,无法观察到soliddashdot之间的差异。 It would be correct if using eg 'linewidth': 1 . 如果使用例如'linewidth': 1是正确的。

在此处输入图片说明

Alternatively you can create your own linestyle, eg 另外,您可以创建自己的线型,例如

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM