python:带有中值和CI的散点图

python:带有中值和CI的散点图,python,median,scatter-plot,Python,Median,Scatter Plot,我正在从我的较大代码块中的剪切粘贴行上寻找python绘图。它没有给我想要的。我是根据埃弗特的建议发帖的 fig = plt.figure(figsize=(8, 8)) plt.plot(xlist, ylist, 'b,') plt.plot([0.0,0.8],[0.0,0.8],'y-') data2d=zip(xlist,ylist) bins = np.linspace(0.0, 0.2, 21) medianlist=binperce

我正在从我的较大代码块中的剪切粘贴行上寻找python绘图。它没有给我想要的。我是根据埃弗特的建议发帖的

    fig = plt.figure(figsize=(8, 8))
    plt.plot(xlist, ylist, 'b,')
    plt.plot([0.0,0.8],[0.0,0.8],'y-')
    data2d=zip(xlist,ylist)
    bins = np.linspace(0.0, 0.2, 21)
    medianlist=binpercentile(data2d,bins)
    c10list=binpercentile(data2d,bins,0.1)
    c90list=binpercentile(data2d,bins,0.9)    
    centerbins=[(x+y)/2.0 for x,y in zip(bins[:-1],bins[1:])]
    centerbins.insert(0,0)
    medianlist.insert(0,0)
    c10list.insert(0,0)
    c90list.insert(0,0)
    plt.plot(centerbins,c10list,'r--')
    plt.plot(centerbins,c90list,'r--')
    plt.plot(centerbins,medianlist,'r-')
    imagefilename='%s.%s'%('.'.join(infile.split('.')[0:-1]),'diffmed.pdf')
    plt.savefig(imagefilename)

从我的大段代码中剪切粘贴。它没有给我想要的。我是根据埃弗特的建议发帖的

    fig = plt.figure(figsize=(8, 8))
    plt.plot(xlist, ylist, 'b,')
    plt.plot([0.0,0.8],[0.0,0.8],'y-')
    data2d=zip(xlist,ylist)
    bins = np.linspace(0.0, 0.2, 21)
    medianlist=binpercentile(data2d,bins)
    c10list=binpercentile(data2d,bins,0.1)
    c90list=binpercentile(data2d,bins,0.9)    
    centerbins=[(x+y)/2.0 for x,y in zip(bins[:-1],bins[1:])]
    centerbins.insert(0,0)
    medianlist.insert(0,0)
    c10list.insert(0,0)
    c90list.insert(0,0)
    plt.plot(centerbins,c10list,'r--')
    plt.plot(centerbins,c90list,'r--')
    plt.plot(centerbins,medianlist,'r-')
    imagefilename='%s.%s'%('.'.join(infile.split('.')[0:-1]),'diffmed.pdf')
    plt.savefig(imagefilename)

这给出了标准偏差带的等效值:

# generate random variables
x,y = generate_random()

# bin the values and determine the envelopes
df = bin_by(x, y, nbins=25, bins = None)

###
# Plot 1
###
# determine the colors
cols = ['#EE7550', '#F19463', '#F6B176']

with plt.style.context('fivethirtyeight'): 
    # plot the 3rd stdv
    plt.fill_between(df.x, df['5th'], df['95th'], alpha=0.7,color = cols[2])
    plt.fill_between(df.x, df['10th'], df['90th'], alpha=0.7,color = cols[1])
    plt.fill_between(df.x, df['25th'], df['75th'], alpha=0.7,color = cols[0])
    # plt the line
    plt.plot(df.x, df['median'], color = '1', alpha = 0.7, linewidth = 1)
    # plot the points
    plt.scatter(x, y, facecolors='white', edgecolors='0', s = 5, lw = 0.7)

plt.savefig('fig1.png', facecolor='white', edgecolor='none')
plt.show()


def bin_by(x, y, nbins=30, bins = None):
    """
    Divide the x axis into sections and return groups of y based on its x value
    """
    if bins is None:
        bins = np.linspace(x.min(), x.max(), nbins)

    bin_space = (bins[-1] - bins[0])/(len(bins)-1)/2

    indicies = np.digitize(x, bins + bin_space)


从my

开始讨论并链接到my Github,这提供了标准偏差带的等效值:

# generate random variables
x,y = generate_random()

# bin the values and determine the envelopes
df = bin_by(x, y, nbins=25, bins = None)

###
# Plot 1
###
# determine the colors
cols = ['#EE7550', '#F19463', '#F6B176']

with plt.style.context('fivethirtyeight'): 
    # plot the 3rd stdv
    plt.fill_between(df.x, df['5th'], df['95th'], alpha=0.7,color = cols[2])
    plt.fill_between(df.x, df['10th'], df['90th'], alpha=0.7,color = cols[1])
    plt.fill_between(df.x, df['25th'], df['75th'], alpha=0.7,color = cols[0])
    # plt the line
    plt.plot(df.x, df['median'], color = '1', alpha = 0.7, linewidth = 1)
    # plot the points
    plt.scatter(x, y, facecolors='white', edgecolors='0', s = 5, lw = 0.7)

plt.savefig('fig1.png', facecolor='white', edgecolor='none')
plt.show()


def bin_by(x, y, nbins=30, bins = None):
    """
    Divide the x axis into sections and return groups of y based on its x value
    """
    if bins is None:
        bins = np.linspace(x.min(), x.max(), nbins)

    bin_space = (bins[-1] - bins[0])/(len(bins)-1)/2

    indicies = np.digitize(x, bins + bin_space)


进行一点讨论,并从my

链接到my Github,到目前为止您有什么收获?你浏览过matplotlib图库吗?粗线为中位数,虚线为10%和90%。问题:线条不平滑。这张图没有R型图漂亮好吧,我明白你的意思了。看起来R插值很多,因为链接图中没有太多的数据点来保证这样高分辨率的“水彩”背景。我不认为matplotlib有这样的功能(看起来它在R中也是很新的),但是也许你可以把你的代码放在这里来生成你的绘图,人们可以对此进行评论,以提高分辨率或使其成为平滑的圆角等高线图。到目前为止你有什么收获?你浏览过matplotlib图库吗?粗线为中位数,虚线为10%和90%。问题:线条不平滑。这张图没有R型图漂亮好吧,我明白你的意思了。看起来R插值很多,因为链接图中没有太多的数据点来保证这样高分辨率的“水彩”背景。我不认为matplotlib有这样的功能(看起来它在R中也是很新的),但是也许你可以把你的代码放在这里来生成你的图,人们可以对此发表评论,以提高分辨率或使它成为平滑的fille等高线图。