1

我正在寻找关于http://www.r-bloggers.com/visually-weighted-watercolor-plots-new-variants-please-vote/行的 python 图

4

2 回答 2

3

这给出了标准偏差带的等价物:

# 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)

水彩情节

一些讨论并从我的博客链接到我的 Github

于 2017-10-03T21:15:52.303 回答
0

从我的大段代码中剪切粘贴。它没有给我想要的东西。我根据 Evert 的建议发布

    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)
于 2012-10-02T16:27:43.100 回答