只是要注意,我已经检查了this questionthis question
因此,我使用distplot在单独的子批次上绘制一些柱状图:

import numpy as np
#import netCDF4 as nc # used to get p0_dict
import matplotlib.pyplot as plt
from collections import OrderedDict
import seaborn.apionly as sns
import cPickle as pickle

'''
LINK TO PICKLE
https://drive.google.com/file/d/0B8Xks3meeDq0aTFYcTZEZGFFVk0/view?usp=sharing
'''

p0_dict = pickle.load(open('/path/to/pickle/test.dat', 'r'))

fig = plt.figure(figsize = (15,10))
ax = plt.gca()
j=1

for region, val in p0_dict.iteritems():

    val = np.asarray(val)

    subax = plt.subplot(5,5,j)

    print region

    try:
        sns.distplot(val, bins=11, hist=True, kde=True, rug=True,
                     ax = subax, color = 'k', norm_hist=True)

    except Exception as Ex:
        print Ex

    subax.set_title(region)
    subax.set_xlim(0, 1) # the data varies from 0 to 1

    j+=1

plt.subplots_adjust(left = 0.06, right = 0.99, bottom = 0.07,
                    top = 0.92, wspace = 0.14, hspace = 0.6)

fig.text(0.5, 0.02, r'$ P(W) = 0,1 $', ha ='center', fontsize = 15)
fig.text(0.02, 0.5, '% occurrence', ha ='center',
         rotation='vertical', fontsize = 15)
# obviously I'd multiply the fractional ticklabels by 100 to get
# the percentage...

plt.show()

我所期望的是kde曲线下的面积总和为1,而y轴勾号标签将反映这一点。但是,我得到以下信息:
python - Seaborn distplot y轴标准化错误的ticklabels-LMLPHP
如您所见,Y轴刻度标签不在范围[0,1]内,如预期的那样。打开/关闭norm_histkde不会改变这一点。作为参考,两个都关闭的输出:
python - Seaborn distplot y轴标准化错误的ticklabels-LMLPHP
只是为了验证:
aus = np.asarray(p0_dict['AUS'])
aus_bins = np.histogram(aus, bins=11)[0]

plt.subplot(121)
plt.hist(aus,11)
plt.subplot(122)
plt.bar(range(0,11),aus_bins.astype(np.float)/np.sum(aus_bins))

plt.show()

python - Seaborn distplot y轴标准化错误的ticklabels-LMLPHP
在这种情况下,Y记号标签正确地反映了标准化的柱状图。
我做错什么了?
谢谢你的帮助。

最佳答案

Y轴是密度,不是概率。我认为你期望标准化的柱状图显示一个概率质量函数,其中条形高度之和等于1。但这是错误的;标准化确保条高与条宽之和等于1。这就确保了归一化的柱状图与核密度估计是可比的,核密度估计是归一化的,因此曲线下的面积等于1。

关于python - Seaborn distplot y轴标准化错误的ticklabels,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32274865/

10-12 17:55