Python matplotlib.pylab.subplot2grid() Examples
The following are 5
code examples of matplotlib.pylab.subplot2grid().
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.pylab
, or try the search function
.
Example #1
Source File: training_dataset_memory.py From deepecg with MIT License | 6 votes |
def plot(self, index): # Get time array time = np.arange(self.length) * 1 / self.fs # Setup plot fig = plt.figure(figsize=(15, 6)) fig.subplots_adjust(hspace=0.25) ax1 = plt.subplot2grid((1, 1), (0, 0)) ax1.set_title( 'File Name: ' + self.labels.loc[index, 'file_name'] + '\n' 'Label: ' + self.labels.loc[index, 'label_str'], fontsize=20 ) # Plot waveform ax1.plot(time, self.data.loc[index, :], '-k', label='Filtered') ax1.set_xlabel('Time, seconds', fontsize=25) ax1.set_ylabel('Normalized Amplitude', fontsize=25) ax1.set_xlim([0, self.duration]) ax1.set_ylim([-0.75, 1.5]) ax1.tick_params(labelsize=18) plt.show()
Example #2
Source File: training_data_validation.py From deepecg with MIT License | 5 votes |
def interval_plot(label_id, labels, path, dataset): """Plot measure vs time.""" # Label lookup label_lookup = {0: 'N', 1: 'A', 2: 'O', 3: '~'} # File name file_name = list(labels.keys())[label_id] # Get label label = labels[file_name] # Load data data = np.load(os.path.join(path, dataset, 'waveforms', file_name + '.npy')) # Time array time = np.arange(data.shape[0]) * 1 / 300 # Setup figure fig = plt.figure(figsize=(15, 5), facecolor='w') fig.subplots_adjust(wspace=0, hspace=0.05) ax1 = plt.subplot2grid((1, 1), (0, 0)) # ECG ax1.set_title('Dataset: {}\nFile Name: {}\nLabel: {}'.format(dataset, file_name, label_lookup[label]), fontsize=20) ax1.plot(time, data, '-k', lw=2) # Axes labels ax1.set_xlabel('Time, seconds', fontsize=20) ax1.set_ylabel('ECG', fontsize=20) ax1.set_xlim([time.min(), time.max()]) plt.yticks(fontsize=12) plt.show()
Example #3
Source File: waveforms.py From deepecg with MIT License | 5 votes |
def plot_waveforms(index, waveforms): """Plots one univariate time series.""" # Get file name file_name = list(waveforms.keys())[index] # Setup plot fig = plt.figure(figsize=(15, 6)) fig.subplots_adjust(hspace=0.25) ax1 = plt.subplot2grid((1, 1), (0, 0)) ax1.set_title( 'File Name: ' + file_name + '\n' 'Label: ' + waveforms[file_name]['label_str'], fontsize=20 ) # Plot waveform ax1.plot(waveforms[file_name]['time'], waveforms[file_name]['filtered'], '-k', label='Filtered') ax1.vlines( waveforms[file_name]['rpeaks_ts'], waveforms[file_name]['filtered'].min() - 0.01, waveforms[file_name]['filtered'].max() + 0.01, color=[0.7, 0.7, 0.7], linewidth=4, label='R-Peaks' ) ax1.set_xlabel('Time, seconds', fontsize=25) ax1.set_ylabel('Normalized Amplitude', fontsize=25) ax1.set_xlim([0, waveforms[file_name]['duration']]) ax1.set_ylim([waveforms[file_name]['filtered'].min() - 0.01, waveforms[file_name]['filtered'].max() + 0.01]) ax1.tick_params(labelsize=18)
Example #4
Source File: elecsus_gui.py From ElecSus with Apache License 2.0 | 4 votes |
def OnCreateResidualPlot(self,fig,canvas): """ Create a plot with main data, residuals and (optionally) histogram of residuals, using subplot2grid in matplotlib """ fig.clf() print('Debugging...') print(self.fit_datatype) print(self.y_optimised) #normalised_residuals = False if self.normalised_residuals: ### not done yet! -- requires error bars in imported data residuals = 100*(self.y_fit_array-self.y_optimised) else: residuals = 100*(self.y_fit_array-self.y_optimised) fig = plt.figure(2) yy = 4 xx = 6 if self.residual_histogram: ax_main = plt.subplot2grid((yy,xx),(0,0),colspan=xx-1,rowspan=yy-1) ax_residual = plt.subplot2grid((yy,xx),(yy-1,0),colspan=xx-1,sharex=ax_main) ax_hist = plt.subplot2grid((yy,xx), (yy-1,xx-1), sharey=ax_residual) plt.setp(ax_hist.get_yticklabels(),visible=False) ax_hist.set_xticklabels([]) else: ax_main = plt.subplot2grid((yy,xx),(0,0),colspan=xx,rowspan=yy-1) ax_residual = plt.subplot2grid((yy,xx),(yy-1,0),colspan=xx,sharex=ax_main) plt.setp(ax_main.get_xticklabels(),visible=False) ax_residual.set_xlabel('Detuning (GHz)') ax_residual.set_ylabel('Residuals (%)') ax_main.set_ylabel(self.expt_type) ax_main.plot(self.x_fit_array,self.y_fit_array,color=d_olive) print(len(self.x_fit_array), len(self.y_optimised)) ax_main.plot(self.x_fit_array,self.y_optimised) ax_residual.plot(self.x_fit_array,residuals,lw=1.25) ax_residual.axhline(0,color='k',linestyle='dashed') if self.residual_histogram: bins = 25 ax_hist.hist(residuals, bins=bins, orientation='horizontal') ax_hist.axhline(0,color='k', linestyle='dashed') ax_main.autoscale_view(tight=True) self._draw_fig(fig,canvas)
Example #5
Source File: state.py From deepecg with MIT License | 4 votes |
def _plot_image(self, index): # Setup figure fig = plt.figure(figsize=(20., 8.), dpi=80) fig.subplots_adjust(wspace=0, hspace=0) ax1 = plt.subplot2grid((2, 1), (0, 0)) ax2 = plt.subplot2grid((2, 1), (1, 0)) # Label lookup label_lookup = ['Normal Sinus Rhythm', 'Atrial Fibrillation', 'Other Rhythm', 'Noisy'] # Get time array time_array = np.arange(self.waveforms.shape[1]) * 1 / 300 # Get labels label = self.labels[index] # Get logits logits = self.logits[index, :] # Get softmax softmax = self._softmax(scores=logits) # Get prediction prediction = int(np.squeeze(np.argmax(softmax))) # Get non-zero-pad indices non_zero_index = np.where(self.waveforms[index, :, 0] != 0)[0] # Title title_string = 'True Label: {}\nPredicted Label: {}\nN: {} % A: {} % O: {} % ~: {} %' ax1.set_title(title_string.format(label_lookup[int(label)], label_lookup[prediction], np.round(softmax[0] * 100., 2), np.round(softmax[1] * 100., 2), np.round(softmax[2] * 100., 2), np.round(softmax[3] * 100., 2)), fontsize=20, y=1.03) # Plot ECG waveform ax1.plot(time_array[non_zero_index], self.waveforms[index, non_zero_index, 0], '-k') ax1.set_xlim([time_array[non_zero_index].min(), time_array[non_zero_index].max()]) ax1.axes.get_xaxis().set_visible(False) ax1.axes.get_yaxis().set_visible(False) # ax1.set_ylabel('Normalized Amplitude', fontsize=22) # ax1.yaxis.set_tick_params(labelsize=16) # Plot Class Activation Map ax2.plot(time_array[non_zero_index], self.cams[index, non_zero_index, prediction], '-k') ax2.set_xlim([time_array[non_zero_index].min(), time_array[non_zero_index].max()]) ax2.axes.get_xaxis().set_visible(False) ax2.axes.get_yaxis().set_visible(False) # ax2.set_xlabel('Time, seconds', fontsize=22) # ax2.set_ylabel('Class Activation Map', fontsize=22) # ax2.xaxis.set_tick_params(labelsize=16) # ax2.yaxis.set_tick_params(labelsize=16) # Get image buffer buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) plt.close(fig) return buf