在同一图中绘制直方图,KDE和正态分布(季节性)

时间:2019-05-10 15:49:33

标签: python matplotlib statistics seaborn

我想在同一张图中绘制直方图,核密度估计图和正态分布。我只能绘制KDE和直方图。如何添加正态分布?

    static void Sample()
    {
        List<string> properties = new List<string>();
        properties.Add("FirstName");
        properties.Add("LastName");

        var exp = generateSelectExpression<User>(properties);
    }

    class User
    {
        public string FirstName;
        public string LastName;
    }

    private static Expression<Func<T, object>> generateSelectExpression<T>(List<string> propertiesToSelect)
    {
        Expression<Func<T, object>> exp = (x) => GetDynamicFromDictionary(GetProperties(x), propertiesToSelect);
        return exp;
    }

    private static dynamic GetDynamicFromDictionary(Dictionary<string,object> dict, List<string> propertiesToSelect)
    {
        var eo = new ExpandoObject();
        var eoColl = (ICollection<KeyValuePair<string, object>>)eo;

        foreach (var kvp in dict)
        {
            if (propertiesToSelect.Contains(kvp.Key))
            {
                eoColl.Add(kvp);
            }
        }

        dynamic eoDynamic = eo;

        return eoDynamic;
    }

    private static Dictionary<string, object> GetProperties(object obj)
    {
        var props = new Dictionary<string, object>();
        if (obj == null)
            return props;

        var type = obj.GetType();
        foreach (var prop in type.GetProperties())
        {
            var val = prop.GetValue(obj, new object[] { });
            props.Add(prop.Name, val);
        }

        return props;
    }

enter image description here

谢谢!

0 个答案:

没有答案