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


Python pyplot.stackplot方法代码示例

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


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

示例1: test_stackplot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def test_stackplot():
    fig = plt.figure()
    x = np.linspace(0, 10, 10)
    y1 = 1.0 * x
    y2 = 2.0 * x + 1
    y3 = 3.0 * x + 2
    ax = fig.add_subplot(1, 1, 1)
    ax.stackplot(x, y1, y2, y3)
    ax.set_xlim((0, 10))
    ax.set_ylim((0, 70)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:12,代码来源:test_axes.py

示例2: test_stackplot_baseline

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def test_stackplot_baseline():
    np.random.seed(0)

    def layers(n, m):
        def bump(a):
            x = 1 / (.1 + np.random.random())
            y = 2 * np.random.random() - .5
            z = 10 / (.1 + np.random.random())
            for i in range(m):
                w = (i / float(m) - y) * z
                a[i] += x * np.exp(-w * w)
        a = np.zeros((m, n))
        for i in range(n):
            for j in range(5):
                bump(a[:, i])
        return a

    d = layers(3, 100)

    fig = plt.figure()

    plt.subplot(2, 2, 1)
    plt.stackplot(list(xrange(100)), d.T, baseline='zero')

    plt.subplot(2, 2, 2)
    plt.stackplot(list(xrange(100)), d.T, baseline='sym')

    plt.subplot(2, 2, 3)
    plt.stackplot(list(xrange(100)), d.T, baseline='wiggle')

    plt.subplot(2, 2, 4)
    plt.stackplot(list(xrange(100)), d.T, baseline='weighted_wiggle') 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:34,代码来源:test_axes.py

示例3: test_stackplot_smoke

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def test_stackplot_smoke():
    # Small smoke test for stackplot (see #12405)
    plt.stackplot([1, 2, 3], [1, 2, 3]) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:5,代码来源:test_pyplot.py

示例4: stack_plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def stack_plot(input_fn, display=False, outfile='stack_plot.png', max_n=20, normalize=False, dont_stack=False):
    data = json.load(open(input_fn))  # TODO do we support multiple arguments here?
    y = numpy.array(data['y'])
    if y.shape[0] > max_n:
        js = sorted(range(len(data['labels'])), key=lambda j: max(y[j]), reverse=True)
        other_sum = numpy.sum(y[j] for j in js[max_n:])
        top_js = sorted(js[:max_n], key=lambda j: data['labels'][j])
        y = numpy.array([y[j] for j in top_js] + [other_sum])
        labels = [data['labels'][j] for j in top_js] + ['other']
    else:
        labels = data['labels']
    if normalize:
        y = 100. * numpy.array(y) / numpy.sum(y, axis=0)
    pyplot.figure(figsize=(13, 8))
    pyplot.style.use('ggplot')
    ts = [dateutil.parser.parse(t) for t in data['ts']]
    colors = generate_n_colors(len(labels))
    if dont_stack:
        for color, label, series in zip(colors, labels, y):
            pyplot.plot(ts, series, color=color, label=label, linewidth=2)
    else:
        pyplot.stackplot(ts, numpy.array(y), labels=labels, colors=colors)
    pyplot.legend(loc=2)
    if normalize:
        pyplot.ylabel('Share of lines of code (%)')
        pyplot.ylim([0, 100])
    else:
        pyplot.ylabel('Lines of code')
    print('Writing output to %s' % outfile)
    pyplot.savefig(outfile)
    pyplot.tight_layout()
    if display:
        pyplot.show() 
开发者ID:erikbern,项目名称:git-of-theseus,代码行数:35,代码来源:stack_plot.py

示例5: PerfMonPlotter

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def PerfMonPlotter(perf_mon_records, time_window = None):
    """
    For plotting performance monitoring records.
    """
    # Entire records
    pqos_records = perf_mon_records['pqos_records']
    # perf_records = perf_mon_records['perf_records']
    # # Select a time window if provided
    # if time_window is not None:
    #     test_start = pqos_records['timestamp'].min()
    #     time_window = [5, 10]
    #     selection_bounds = [test_start + timedelta(seconds=time_window[0]), \
    #                         test_start + timedelta(seconds=time_window[1])]
    #     pqos_records['In Test Bound'] = (pqos_records['timestamp']>selection_bounds[0]) \
    #                                     & (pqos_records['timestamp']<selection_bounds[1])
    #     perf_records['In Test Bound'] = (perf_records['timestamp']>time_window[0]) \
    #                                     & (perf_records['timestamp']<time_window[1])
    #     pqos_df = pqos_records[pqos_records['In Test Bound']==True]
    #     perf_df = perf_records[perf_records['In Test Bound']==True]

    palette = sns.color_palette("rocket_r", 16)
    
    # 'timestamp','Core','IPC','LLC Misses','LLC Util (KB)','MBL (MB/s)'
    fig, axs = plt.subplots(ncols=2, nrows=2, sharex=True)
    pqos_records_sum = pqos_records.groupby('timestamp').sum()
    pqos_records_sum.plot(y='IPC', ax=axs[0][0])
    pqos_records_sum.plot(y='MBL (MB/s)', ax=axs[0][1])
    pqos_records_sum.plot(y='LLC Util (KB)', ax=axs[1][0])
    pqos_records_sum.plot(y='LLC Misses', ax=axs[1][1])
    axs[0][0].set_ylim([0,20])

    # sns.relplot(data=pqos_records, x='timestamp', y='IPC', hue='Core', kind='line', palette=palette, alpha=0.75)
    # sns.relplot(data=pqos_records, x='timestamp', y='MBL (MB/s)', hue='Core', kind='scatter', palette=palette, alpha=0.75)
    # sns.lmplot(data=pqos_df.groupby('timestamp').sum(), x='IPC', y='MBL (MB/s)', palette=palette,
    #            truncate=True, order=5, fit_reg=False, scatter_kws={'alpha':0.5}, legend_out=False)
    # sns.jointplot(data=pqos_df.groupby('timestamp').sum(), x='LLC Util (KB)', y='MBL (MB/s)', kind="hex", zorder=0)
                #  .plot_joint(sns.kdeplot, zorder=10, n_levels=25, bw='silverman')

    # cpu-cycles,L1-dcache-loads,L1-dcache-load-misses,L1-icache-load-misses,dTLB-load-misses,dTLB-loads,
    # iTLB-load-misses,iTLB-loads,branch-misses,context-switches,cpu-migrations,page-faults
    # sns.relplot(data=perf_records, x='timestamp', y='context-switches', kind='line', palette=palette, alpha=0.75)
    # plt.stackplot(perf_records['timestamp'], perf_records['r4f1'], perf_records['r2f1'], perf_records['r1f1'])
    # sns.relplot(data=perf_df, x='context-switches', y='r1f1', kind='scatter', palette=palette, alpha=0.75)
    # perf_records['Branch Miss Rate (%)'] = 100.0*perf_records['branch-misses']/perf_records['branches']
    # sns.lmplot(data=perf_records, x='context-switches', y='block:block_plug',
    #            truncate=True, order=8, scatter_kws={'alpha':0.5}, legend_out=False)
    # sns.jointplot(data=perf_df, x='dTLB-loads', y='iTLB-loads', kind="hex", zorder=0)

    plt.show()
    plt.close()

    return True 
开发者ID:PrincetonUniversity,项目名称:faas-profiler,代码行数:54,代码来源:TestDataframePlotting.py

示例6: stackplot_non_text_messages_percentage

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def stackplot_non_text_messages_percentage(msgs, path_to_save):
    sns.set(style="whitegrid", palette="muted")

    colors = ['y', 'b', 'c', 'r', 'g', 'm']

    (x, y_total), (xticks, xticks_labels, xlabel) = _get_plot_data(msgs), _get_xticks(msgs)

    stacks = stools.get_non_text_messages_grouped(y_total)

    # Normalize values
    for i in range(len(stacks[0]["groups"])):
        total = sum(stack["groups"][i] for stack in stacks)
        for stack in stacks:
            if not total:
                stack["groups"][i] = 0
            else:
                stack["groups"][i] /= total

    plt.stackplot(x, *[stack["groups"] for stack in stacks], labels=[stack["type"] for stack in stacks],
                  colors=colors, alpha=0.7)

    plt.margins(0, 0)
    plt.xticks(xticks, rotation=65)
    plt.yticks([i / 10 for i in range(0, 11, 2)])

    ax = plt.gca()
    ax.set_xticklabels(xticks_labels)
    ax.set_yticklabels([f"{i}%" for i in range(0, 101, 20)])
    ax.tick_params(axis='x', bottom=True, color="#A9A9A9")
    ax.set(xlabel=xlabel, ylabel="non-text messages")

    # https://stackoverflow.com/a/4701285
    # Shrink current axis by 10%
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.9, box.height])
    # Put a legend to the right of the current axis
    ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))

    fig = plt.gcf()
    fig.set_size_inches(11, 8)

    fig.savefig(os.path.join(path_to_save, stackplot_non_text_messages_percentage.__name__ + ".png"), dpi=500)
    # plt.show()
    log_line(f"{stackplot_non_text_messages_percentage.__name__} was created.")
    plt.close("all") 
开发者ID:vlajnaya-mol,项目名称:message-analyser,代码行数:47,代码来源:plotter.py

示例7: fraction_timeseries

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import stackplot [as 别名]
def fraction_timeseries(
    adata,
    xkey="clusters",
    tkey="dpt_pseudotime",
    bins=30,
    legend_loc="best",
    title=None,
    fontsize=None,
    ax=None,
    figsize=None,
    dpi=None,
    xlabel=None,
    ylabel=None,
    show=True,
):
    t = np.linspace(0, 1 + 1 / bins, bins)
    types = np.unique(adata.obs[xkey].values)

    y = []
    for i in range(bins - 1):
        mask = np.all(
            [adata.obs[tkey].values <= t[i + 1], adata.obs[tkey].values > t[i]], axis=0
        )
        x = list(adata[mask].obs[xkey].values)
        y.append([])
        for name in types:
            occur = x.count(name)
            y[-1].append(occur)
        y[-1] /= np.sum(y[-1])
    y = np.array(y).T

    ax = pl.figure(figsize=figsize, dpi=dpi) if ax is None else ax

    c = None
    if "clusters_colors" in adata.uns.keys():
        c = adata.uns["clusters_colors"]
    pl.stackplot(t[:-1], y, baseline="zero", labels=types, colors=c, edgecolor="white")

    pl.legend(types, loc=legend_loc)
    if title is not None:
        pl.title(title, fontsize=fontsize)
    pl.xlabel(tkey if xlabel is None else xlabel, fontsize=fontsize)
    pl.ylabel(f"{xkey} fractions" if ylabel is None else ylabel, fontsize=fontsize)
    pl.xlim(adata.obs[tkey].values.min(), adata.obs[tkey].values.max())
    pl.ylim(0, 1)

    if not show:
        return ax
    else:
        pl.show() 
开发者ID:theislab,项目名称:scvelo,代码行数:52,代码来源:utils.py


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