當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。