Python matplotlib.pyplot.Subplot() Examples
The following are 6
code examples of matplotlib.pyplot.Subplot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: visualize.py From pre-trained-keras-example with MIT License | 6 votes |
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
Example #2
Source File: spots.py From allesfitter with MIT License | 6 votes |
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
Example #3
Source File: cam_animation.py From pre-trained-keras-example with MIT License | 5 votes |
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)
Example #4
Source File: plotARContour.py From ar-pde-cnn with MIT License | 5 votes |
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()
Example #5
Source File: plotBARContour.py From ar-pde-cnn with MIT License | 5 votes |
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()
Example #6
Source File: util.py From bayes_nn with MIT License | 4 votes |
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)