本文整理汇总了Python中matplotlib.pylab.subplot2grid方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.subplot2grid方法的具体用法?Python pylab.subplot2grid怎么用?Python pylab.subplot2grid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pylab
的用法示例。
在下文中一共展示了pylab.subplot2grid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import subplot2grid [as 别名]
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()
示例2: interval_plot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import subplot2grid [as 别名]
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()
示例3: plot_waveforms
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import subplot2grid [as 别名]
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)
示例4: OnCreateResidualPlot
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import subplot2grid [as 别名]
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)
示例5: _plot_image
# 需要导入模块: from matplotlib import pylab [as 别名]
# 或者: from matplotlib.pylab import subplot2grid [as 别名]
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