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


Python pyplot.Subplot方法代码示例

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


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

示例1: plot_prediction

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def plot_prediction(pixels, model, data_encoder):
    fig = plt.figure()
    inner = gridspec.GridSpec(2, 1, wspace=0.05, hspace=0, height_ratios=[5, 1.2])
    image_ax = plt.Subplot(fig, inner[0])
    labels_ax = plt.Subplot(fig, inner[1])

    predicted_labels = model.predict(np.array([pixels]), batch_size=1)
    character_name_to_probability = data_encoder.one_hot_decode(predicted_labels[0].astype(np.float64))
    top_character_probability = sorted(character_name_to_probability.items(),
                                       key=lambda item_tup: item_tup[1],
                                       reverse=True)[:3]
    top_character_names, top_character_probabilities = zip(*top_character_probability)
    character_idx = data_encoder.one_hot_index(top_character_names[0])

    plot_row_item(image_ax, labels_ax, pixels, top_character_names, top_character_probabilities)

    fig.add_subplot(image_ax)
    fig.add_subplot(labels_ax)
    return fig 
开发者ID:innolitics,项目名称:pre-trained-keras-example,代码行数:21,代码来源:visualize.py

示例2: setup_grid

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def setup_grid():
    fig = plt.figure(figsize=(8,3.8))
    
    gs0 = gridspec.GridSpec(1, 2)
    
    gs00 = gridspec.GridSpecFromSubplotSpec(4, 1, subplot_spec=gs0[0], hspace=0)
    ax1 = plt.Subplot(fig, gs00[:-1, :])
    ax1.set(xlabel='', xticks=[], ylabel='Flux')
    fig.add_subplot(ax1)
    ax2 = plt.Subplot(fig, gs00[-1, :])
    ax2.set(xlabel='Phase', ylabel='Res.')
    fig.add_subplot(ax2)
    
    
    gs01 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs0[1])
    ax3 = plt.Subplot(fig, gs01[:, :])
    ax3.set(xlabel='Long. (deg)', ylabel='Lat. (deg.)')
    fig.add_subplot(ax3)
    
    plt.tight_layout()
    return fig, ax1, ax2, ax3 
开发者ID:MNGuenther,项目名称:allesfitter,代码行数:23,代码来源:spots.py

示例3: make_cam_plot

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def make_cam_plot(model, weight, image_path, cam_path, data_generator):
    path_head, npz_name = os.path.split(image_path)
    _, character_name = os.path.split(path_head)

    model_name = os.path.basename(os.path.dirname(weight))

    character_idx = data_generator.encoder.one_hot_index(character_name)
    cam = cam_weighted_image(model, image_path, character_idx)

    fig = plt.figure()
    inner = gridspec.GridSpec(2, 1, wspace=0.05, hspace=0, height_ratios=[5, 1.2])
    image_ax = plt.Subplot(fig, inner[0])
    labels_ax = plt.Subplot(fig, inner[1])
    character_name_to_probability = get_model_predictions_for_npz(model,
                                                                  data_generator,
                                                                  character_name,
                                                                  npz_name)
    top_character_probability = sorted(character_name_to_probability.items(),
                                       key=lambda item_tup: item_tup[1],
                                       reverse=True)[:3]
    top_character_names, top_character_probabilities = zip(*top_character_probability)

    plot_row_item(image_ax, labels_ax, cam, top_character_names, top_character_probabilities)
    weight_idx = os.path.basename(weight).split('.')[1]
    labels_ax.set_xlabel(npz_name)
    image_ax.set_title(model_name + ', epoch ' + weight_idx)

    fig.add_subplot(image_ax)
    fig.add_subplot(labels_ax)

    plt.savefig(os.path.join(cam_path, 'cam_{}.png'.format(weight_idx)))
    plt.close(fig) 
开发者ID:innolitics,项目名称:pre-trained-keras-example,代码行数:34,代码来源:cam_animation.py

示例4: plotContourGrid

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def plotContourGrid(t, xT, uPred, uTarget):
    '''
    Creates grid of 4 different test cases, plots target, prediction and error for each
    '''
    mpl.rcParams['font.family'] = ['serif'] # default is sans-serif
    rc('text', usetex=False)

    fig = plt.figure(figsize=(15, 9), dpi=150)
    outer = gridspec.GridSpec(2, 2, wspace=0.45, hspace=0.2) # Outer grid
    for i in range(4):
        # Inner grid
        inner = gridspec.GridSpecFromSubplotSpec(3, 1, 
            subplot_spec=outer[i], wspace=0, hspace=0.2)
        ax = []
        for j in range(3):
            ax0 = plt.Subplot(fig, inner[j])
            fig.add_subplot(ax0)
            ax.append(ax0)
        # Plot specific test case
        plotPred(fig, ax, t, xT, uPred[i], uTarget[i])

    file_dir = '.'
    # If directory does not exist create it
    if not os.path.exists(file_dir):
        os.makedirs(file_dir)
    file_name = file_dir+"/burger_AR_pred"
    plt.savefig(file_name+".png", bbox_inches='tight')
    plt.savefig(file_name+".pdf", bbox_inches='tight')

    plt.show() 
开发者ID:cics-nd,项目名称:ar-pde-cnn,代码行数:32,代码来源:plotARContour.py

示例5: plotContourGrid

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def plotContourGrid(t, xT, uPred, betas, uTarget):
    '''
    Creates grid of 4 different test cases, plots target, prediction, variance and error for each
    '''
    mpl.rcParams['font.family'] = ['serif'] # default is sans-serif
    rc('text', usetex=False)

    fig = plt.figure(figsize=(15, 13), dpi=150)
    outer = gridspec.GridSpec(2, 2, wspace=0.45, hspace=0.2) # Outer grid
    for i in range(4):
        # Inner grid
        inner = gridspec.GridSpecFromSubplotSpec(4, 1, 
            subplot_spec=outer[i], wspace=0, hspace=0.25)
        ax = []
        for j in range(4):
            ax0 = plt.Subplot(fig, inner[j])
            fig.add_subplot(ax0)
            ax.append(ax0)
        # Plot specific test case
        plotPred(fig, ax, t, xT, uPred[i], betas, uTarget[i])

    file_dir = '.'
    # If directory does not exist create it
    if not os.path.exists(file_dir):
        os.makedirs(file_dir)
    file_name = file_dir+"/burger_BAR_pred"
    plt.savefig(file_name+".png", bbox_inches='tight')
    plt.savefig(file_name+".pdf", bbox_inches='tight')

    plt.show() 
开发者ID:cics-nd,项目名称:ar-pde-cnn,代码行数:32,代码来源:plotBARContour.py

示例6: plot_preds

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Subplot [as 别名]
def plot_preds(preds, batch):
    """
    Lots of matplotlib magic to plot the predictions
    :param preds:
    :param batch: tuple of images, labels
    :return:
    """
    images, labels = batch
    if isinstance(preds, list):
        preds = np.stack(preds)

    num_samples, num_batch, num_classes = preds.shape

    ave_preds = np.mean(preds, 0)
    pred_class = np.argmax(ave_preds, 1)

    entropy, variance, _, _ = calc_risk(preds)

    # Do all the plotting

    for n in range(num_batch):
        fig = plt.figure(figsize=(10, 8))
        outer = gridspec.GridSpec(1, 2, wspace=0.2, hspace=0.2)

        half = gridspec.GridSpecFromSubplotSpec(4, 4, subplot_spec=outer[0], wspace=0.1, hspace=0.1)
        colors = get_color(pred_class[n], labels[n])
        for num_sample in range(half._ncols * half._nrows):
            ax = plt.Subplot(fig, half[num_sample])
            ax.bar(range(10), preds[num_sample, n], color=colors)
            ax.set_ylim(0, np.max(preds))
            ax.set_xticks([])
            ax.set_yticks([])
            fig.add_subplot(ax)

        half = gridspec.GridSpecFromSubplotSpec(3, 1, subplot_spec=outer[1], wspace=0.1, hspace=0.1)

        ax = plt.Subplot(fig, half[0])
        ax.imshow(np.squeeze(images[n]))
        fig.add_subplot(ax)

        ax = plt.Subplot(fig, half[1])
        ax.bar(range(10), ave_preds[n], color=colors)
        ax.set_ylim(0, np.max(preds))
        ax.set_xticks([])
        fig.add_subplot(ax)

        ax = plt.Subplot(fig, half[2])
        t = ax.text(0.5, 0.5, 'Entropy %7.3f \n Std %7.3f' % (entropy[n], variance[n]))
        t.set_ha('center')
        fig.add_subplot(ax)

        # fig.show()
        plt.savefig('im/plot%i.png' % n) 
开发者ID:RobRomijnders,项目名称:bayes_nn,代码行数:55,代码来源:util.py


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