当前位置: 首页>>代码示例>>Python>>正文


Python pyplot.stackplot函数代码示例

本文整理汇总了Python中matplotlib.pyplot.stackplot函数的典型用法代码示例。如果您正苦于以下问题:Python stackplot函数的具体用法?Python stackplot怎么用?Python stackplot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了stackplot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: stackplot

def stackplot(data, x, y, hue, cmap=palettes.neon):
    xs = np.array(data[x])
    yss = []
    labels = []
    for k,grp in data.groupby(hue):
        labels.append(k)
        grp_xs = grp[x].tolist()
        grp_ys = grp[y].tolist()
        ys = []
        for v in xs:
            if len(grp_xs) > 0 and grp_xs[0] == v:
                ys.append(grp_ys.pop(0))
                grp_xs.pop(0)
            else:
                if len(ys) == 0:
                    ys.append(0.)
                else:
                    ys.append(ys[-1])
        assert len(grp_xs) == 0
        assert len(grp_ys) == 0
        assert len(ys) == len(xs)
        yss.append(np.array(ys, dtype=float))

    if cmap is not None:
        colors = colors_from_hue(data, hue, cmap)
    else:
        colors = None

    plt.stackplot(xs, *yss, labels=labels, colors=colors)

    plt.ylabel(y)
    plt.xlabel(x)
    plt.gca().autoscale(tight=True)
    plt.gca().margins(y=0.1)
开发者ID:brucespang,项目名称:plorts,代码行数:34,代码来源:plotting.py

示例2: plot3

def plot3():
### number of settlements, cropping: abandoned/sown, soil degradation, total real income
    fig = plt.figure(figsize=(12,7))
    crop_yield_evo[np.isnan(crop_yield_evo)]=0
    
    ### number of settlements
    plt.subplot(221)
    plt.plot(crop_yield_evo)
    plt.title("crop yield")
    
    ### ecoserv benefit 
    plt.subplot(222)
    plt.plot(eco_benefit_evo)
    plt.title("eco benefit")
    
    ### soil degradation
    plt.subplot(223)
    plt.plot(trade_income_evo)
    plt.title("trade strength")
    
    ### total real income
    plt.subplot(224)
    plt.stackplot(np.arange(N),np.nanmean(crop_yield_evo,1)*1.1,np.nanmean(eco_benefit_evo,1)*10,np.nanmean(trade_income_evo,1)*6000)
    plt.title("total real income")
    
    plt.tight_layout()
    fig.savefig(picture_directory+'3_panel.png',dpi=200)
    plt.close(fig)
开发者ID:jakobkolb,项目名称:MayaSim,代码行数:28,代码来源:data_visualisation.py

示例3: stack_plot

def stack_plot(fr, outfile, normalize=False, dont_stack=False, max_n=20):

    
    if len(fr.columns) > max_n: # reformat columns and group together nonsignificant ones
        
        js = sorted([ (c,fr[c].sum()) for c in fr.columns ], key=lambda j: j[1], reverse=True)
        top_js  = [ i[0] for i in js[:max_n]]
        rest_js = [ i[0] for i in js[max_n:]]
        # replace
        fr['Others']=fr[rest_js].sum(axis=1)
        # remove
        fr=fr.drop(rest_js, axis=1)
        labels = top_js+['Others']
    else:
        js = sorted([ (c,fr[c].sum()) for c in fr.columns ], key=lambda j: j[1], reverse=True)
        labels  = [ i[0] for i in js]
        
    pyplot.figure(figsize=(13, 8))
    
    colors = generate_n_colors(len(labels))
    if dont_stack:
        for color, label in zip(colors, labels):
            pyplot.plot(fr.index, fr[label], color=color, label=label, linewidth=2)
    else:
        pyplot.stackplot(fr.index, fr[labels].T, labels=labels)#, colors=colors
        #fr.plot(kind='area')
        
    pyplot.legend(loc=2)
    pyplot.ylabel('Lines of code')
    pyplot.tight_layout()
    pyplot.savefig(outfile)
开发者ID:BIC-MNI,项目名称:minc-toolkit-v2,代码行数:31,代码来源:stack_plot.py

示例4: plot_stack_candidates

def plot_stack_candidates(tweets, cands, interval, start = 0, \
  end = MAX_TIME // 60, tic_inc = 120, save_to = None): 
  '''
  Plots stackplot for the candidates in list cands over the time interval
  ''' 

  period = range(start, end, interval)
  percent_dict = tweets.mention_minute_percent(cands, interval, period)

  y = [] 
  fig = plt.figure(figsize = (FIGWIDTH, FIGHEIGHT))
  legends = [] 
  for candidate in percent_dict:
    y.append(percent_dict[candidate]) 
    legends.append(CANDIDATE_NAMES[candidate])
  plt.stackplot(period, y)

  plt.title("Percentage of Mentions per {} minutes before, during, \
    and after debate".format(interval))
  plt.xlabel("Time")
  plt.ylabel("Number of Tweets")
  plt.legend(y, legends)

  ticks_range = range(start, end, tic_inc)
  labels = list(map(lambda x: str(x - start) + " min", ticks_range))
  plt.xticks(ticks_range, labels, rotation = 'vertical')
  plt.xlim( (start, end) )
  plt.ylim( (0.0, 1.0))
  
  if save_to: 
    fig.savefig(save_to)
  plt.show()
开发者ID:karljiangster,项目名称:Python-Fun-Stuff,代码行数:32,代码来源:debate_tweets.py

示例5: plot2

def plot2():
    ### number of settlements,cropping: abandoned/sown, soil degradation, forest state
    fig = plt.figure(figsize=(12, 7))
    
    ### number of settlements
    plt.subplot(221)
    plt.plot(number_settlements_evo)
    plt.title("number of settlements")
    
    ### cropping: abandoned/sown
    plt.subplot(222)
    plt.plot(abnd_sown_evo[:, 0], "r")
    plt.plot(abnd_sown_evo[:, 1], "g")
    plt.title("abandoned/sown")
    
    ### soil degradation
    plt.subplot(223)
    plt.plot(soil_deg_evo[0])
    plt.title("soil degradation")
    
    ### forest state
    plt.subplot(224)
    plt.stackplot(np.arange(N),forest_evo[0],forest_evo[1],forest_evo[2],colors=['#FF9900', '#66FF33','#336600'])
    plt.title("forest state")
    
    plt.tight_layout()
    fig.savefig(picture_directory+'2_panel.png',dpi=200)
    plt.close(fig)
开发者ID:jakobkolb,项目名称:MayaSim,代码行数:28,代码来源:mayasim_visuals.py

示例6: stacked_trajectory_plot

def stacked_trajectory_plot(xlabel="generation"):
    colors_lighter = [
        "#A567AF",
        "#8F69C1",
        "#8474D1",
        "#7F85DB",
        "#7F97DF",
        "#82A8DD",
        "#88B5D5",
        "#8FC0C9",
        "#97C8BC",
        "#A1CDAD",
        "#ACD1A0",
        "#B9D395",
        "#C6D38C",
        "#D3D285",
        "#DECE81",
        "#E8C77D",
        "#EDBB7A",
        "#EEAB77",
        "#ED9773",
        "#EA816F",
        "#E76B6B",
    ]
    mpl.rcParams["font.size"] = 18
    haplotypes = get_all_haplotypes()
    trajectories = [get_trajectory(haplotype) for haplotype in haplotypes]
    plt.stackplot(range(generations), trajectories, colors=colors_lighter)
    plt.ylim(0, 1)
    plt.ylabel("frequency")
    plt.xlabel(xlabel)
开发者ID:mlbendall,项目名称:SISMID-Module15,代码行数:31,代码来源:mutation-drift.py

示例7: plot

  def plot(self):
    # Read events.
    #self.read_simple_events()
    #self.read_external_events()
    self.read_events()
    self.scale(self.scale_factor)
    
    # Set the plot size.
    grid_row = 2
    grid_fig_col = self.num_simple_events / 2
    grid_legend_col = 8
    grid_col = grid_fig_col + grid_legend_col
    fig = plt.figure(figsize = (grid_col, grid_row * 6))

    # Plot simple events.
    plt.subplot2grid((grid_row, grid_col), (0, 0), colspan = grid_fig_col)
    x = np.arange(self.num_simple_events)
    # Prepare colors.
    colors = self.get_colors(len(V8_STATES_PLOT))
    plt.stackplot(x, [self.data[key] for key in V8_STATES_PLOT], colors = colors)
    # Set the axis limits.
    plt.xlim(xmin = 0, xmax = self.num_simple_events - 1)
    plt.ylim(ymin = 0, ymax = self.sampling_period)
    # Draw legend.
    plt.subplot2grid((grid_row, grid_col), (0, grid_col - 1))
    total_ticks = self.num_simple_events * self.sampling_period
    plt.table(cellText = [[str(100 * sum(self.data[key]) / total_ticks) + ' %'] for key in reversed(V8_STATES_PLOT)],
              rowLabels = V8_STATES_PLOT[::-1],
              rowColours = colors[::-1],
              colLabels = ['Ticks'],
              loc = 'center')
    plt.xticks([])
    plt.yticks([])
    
    # Plot external events.
    plt.subplot2grid((grid_row, grid_col), (1, 0), colspan = grid_fig_col)
    x = np.arange(self.num_external_events)
    # Prepare colors.
    colors = self.get_colors(len(EXTERNAL_DETAILS))
    plt.stackplot(x, [self.data_external[key] for key in EXTERNAL_DETAILS], colors = colors)
    # Set the axis limits.
    plt.xlim(xmin = 0, xmax = self.num_external_events - 1)
    plt.ylim(ymin = 0, ymax = self.sampling_period)
    # Draw legend.
    plt.subplot2grid((grid_row, grid_col), (1, grid_col - 3), colspan = 3)
    total_ticks = 0
    for key in EXTERNAL_DETAILS:
      total_ticks += sum(self.data_external[key]) + 1
    plt.table(cellText = [[str(100 * sum(self.data_external[key]) / total_ticks) + ' %', str(sum(self.num_external[key]))] for key in reversed(EXTERNAL_DETAILS)],
              rowLabels = EXTERNAL_DETAILS[::-1],
              rowColours = colors[::-1],
              colLabels = ['Ticks', '# of Times'],
              loc = 'center')
    plt.xticks([])
    plt.yticks([])
    
    # Finally draw the plot.
    plt.tight_layout()
    plt.show()
开发者ID:jray319,项目名称:v8_simulation,代码行数:59,代码来源:plot.py

示例8: stacked_trajectory_plot

def stacked_trajectory_plot(xlabel="generation"):
    mpl.rcParams['font.size']=18
    haplotypes = get_all_haplotypes()
    trajectories = [get_trajectory(haplotype) for haplotype in haplotypes]
    plt.stackplot(range(generations), trajectories, colors=colors_lighter)
    plt.ylim(0, 1)
    plt.ylabel("frequency")
    plt.xlabel(xlabel)
开发者ID:alvason,项目名称:probability-insighter,代码行数:8,代码来源:mutation-drift-selection.py

示例9: stackPlot

    def stackPlot(self, mergeMeth, xAxis, lst1, lst, lst3):
        xLims = plt.xlim(-.05, (xAxis +.05))
        yLims = plt.ylim(0, max(mergeMeth) + 1)


        #fig, ax = plt.subplots()
        plt.stackplot(xAxis, lst1, lst2, lst3, colors=['m','c','y'])
        plt.show()
开发者ID:brittbinler,项目名称:truel,代码行数:8,代码来源:expectedBullets2.py

示例10: makePlot

def makePlot(fn=getCosDistribution):
    # collect data
    h = 60
    linePlots = []
    stackedPlots = {
        'labels': [],
        'data': [],
        'colors': [],
    }
    for line in lines:
        distribution = fn(line['schedule'], line['capacity'])
        distribution = rotate(distribution, -line.get('offset', 0))
        distribution = distribution[3*h:] + distribution[:3*h]
        distribution = distribution[1*h:23*h]
        if line.get('stacked'):
            stackedPlots['data'  ].append(distribution)
            stackedPlots['colors'].append(line['color'])
            stackedPlots['labels'].append(line['line'])            
            
        else:
            linePlots.append({
                'y': distribution,
                'color': line['color'],
                'linestyle': line.get('linestyle', '-'),
                'linewidth': line.get('linewidth', 2),
                'alpha': line.get('alpha', 1),
            })
    X = [t/60.0 for t in  range(4*h, 26*h)]

    # make plot
    matplotlib.rcParams.update({'font.size': 16})
    fig, ax = plot.subplots(facecolor="white", figsize=(13,7), dpi=100)
    ax.xaxis.set_major_formatter(ticker.FuncFormatter(lambda d, _: str(d%24)+"h"))
    ax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda d, _: "{:,}".format(int(d))))
    plot.xlim(4, 26)
    plot.ylim(0, 35000)
    plot.xticks(range(4,27, 2))
    plot.ticklabel_format(axis='x',)
    plot.minorticks_on()
    plot.grid(color='#000000', alpha=0.2, linestyle='-', linewidth=0.8, which='both')
    ax.yaxis.grid(color='#000000', alpha=0.1, linestyle='-', linewidth=0.4, which='minor')
#    plot.grid(color='#000000', b=True, which='minor', axis='x', alpha=0.15, linestyle='-', linewidth=0.5, xdata=range(5,27, 2))
    ax.xaxis.set_minor_locator(ticker.AutoMinorLocator(2))

    if len(stackedPlots['data']) > 0:
        plot.stackplot(X,
                       *(stackedPlots['data']),
                       colors=stackedPlots['colors'],
                       alpha = 0.5,
                       linewidth = 0)
    for p in linePlots:
        plot.plot(X,
                  p['y'],
                  alpha=p['alpha'],
                  color=p['color'], linewidth=p['linewidth'], linestyle=p['linestyle'],)
#    plot.axes(axisbg='w')

    plot.show()
开发者ID:ant6n,项目名称:montreal-rem-capacity-graph,代码行数:58,代码来源:frequencies.py

示例11: plot_population_drift

def plot_population_drift(drift_data, title):
    generations = range(drift_data.shape[1])
    xs = range(drift_data.shape[0])
    colors = [str(hex(SKIN_COLORS[x])).replace("0x", "#") for x in xs]
    plt.stackplot(generations, drift_data, baseline="zero", colors=colors)
    plt.xlabel("Generations")
    plt.ylabel("Frequency")
    plt.title("Phenotype Drift:%s" % (title))
    plt.show()
开发者ID:amit93,项目名称:mlia-examples,代码行数:9,代码来源:skin_colors.py

示例12: stacked

def stacked(asim, msim):
    if len(asim) != len(msim):
        raise Exception("The Replacement and Maintenance sets arent the same lenght")
    else:
        plt.stackplot(range(0, len(asim)), [asim, msim], colors=["#377EB8", "#55BA87"])
        plt.legend([mpatches.Patch(color="#377EB8"), mpatches.Patch(color="#55BA87")], ["Replacement", "Maintenance"])
        plt.title("Expected Financial Consequence - Replacement & Maintenance")
        plt.xlabel("Years")
        plt.ylabel("Fin. Consequence (k)")
开发者ID:akarimuk,项目名称:crystall-ball,代码行数:9,代码来源:pbp_functions.py

示例13: stacked_trajectory_plot

def stacked_trajectory_plot(history, generations, name = 'stacked_trajectory', xlabel="generation"):
    colors_lighter = ["#A567AF", "#8F69C1", "#8474D1", "#7F85DB", "#7F97DF", "#82A8DD", "#88B5D5", "#8FC0C9", "#97C8BC", "#A1CDAD", "#ACD1A0", "#B9D395", "#C6D38C", "#D3D285", "#DECE81", "#E8C77D", "#EDBB7A", "#EEAB77", "#ED9773", "#EA816F", "#E76B6B"]
    mpl.rcParams['font.size']=18
    haplotypes = get_all_haplotypes(history, generations)
    trajectories = [get_trajectory(haplotype, generations, history) for haplotype in haplotypes]
    plt.stackplot(range(generations), trajectories, colors=colors_lighter)
    plt.ylim(0, 1)
    plt.ylabel("frequency")
    plt.xlabel(xlabel)
    plt.savefig(name + '.png', bbox_inches='tight',  dpi = 600)
开发者ID:LennonLab,项目名称:MutationDorm,代码行数:10,代码来源:quantifyPop.py

示例14: plotLats

def plotLats(classifNr,dx):

	x = [classifNr[i] for i in classifNr]
	n = 180/dx + 1
	y = np.arange(-90,90+dx,dx)
	fig = plt.figure()
	plt.stackplot(y,x,alpha = 0.4,colors = colors)
	plt.margins(0,0)
	plt.title('Classifications and latitudes, percentage')
	plt.xlabel('Latitudes')
	plt.xticks(y)
	plt.show()
开发者ID:hjonasson,项目名称:DataMining,代码行数:12,代码来源:analyze.py

示例15: test05

def test05():
    k = [1,2,3,4,5]

    a = [2,3,2,3,2]
    b = [4,1,5,3,5]
    c = [1,4,2,2,3]
    d = [3,2,1,2,0]

    plt.stackplot(k, a, b, c, d, colors=['r', 'g', 'b', 'y'])
    plt.plot([],[],label='a',color='r',linewidth=5)
    plt.plot([],[],label='b',color='g',linewidth=5)
    plt.plot([],[],label='c',color='b',linewidth=5)
    plt.plot([],[],label='d',color='y',linewidth=5)
开发者ID:rkhullar,项目名称:pyplot-demo,代码行数:13,代码来源:target.py


注:本文中的matplotlib.pyplot.stackplot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。