本文整理汇总了Python中matplotlib.image.NonUniformImage.set_cmap方法的典型用法代码示例。如果您正苦于以下问题:Python NonUniformImage.set_cmap方法的具体用法?Python NonUniformImage.set_cmap怎么用?Python NonUniformImage.set_cmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.image.NonUniformImage
的用法示例。
在下文中一共展示了NonUniformImage.set_cmap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_time_frequency
# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_cmap [as 别名]
def plot_time_frequency(spectrum, interpolation='bilinear',
background_color=None, clim=None, dbscale=True, **kwargs):
"""
Time-frequency plot. Modeled after image_nonuniform.py example
spectrum is a dataframe with frequencies in columns and time in rows
"""
if spectrum is None:
return None
times = spectrum.index
freqs = spectrum.columns
if dbscale:
z = 10 * np.log10(spectrum.T)
else:
z = spectrum.T
ax = plt.figure().add_subplot(111)
extent = (times[0], times[-1], freqs[0], freqs[-1])
im = NonUniformImage(ax, interpolation=interpolation, extent=extent)
if background_color:
im.get_cmap().set_bad(kwargs['background_color'])
else:
z[np.isnan(z)] = 0.0 # replace missing values with 0 color
if clim:
im.set_clim(clim)
if 'cmap' in kwargs:
im.set_cmap(kwargs['cmap'])
im.set_data(times, freqs, z)
ax.set_xlim(extent[0], extent[1])
ax.set_ylim(extent[2], extent[3])
ax.images.append(im)
if 'colorbar_label' in kwargs:
plt.colorbar(im, label=kwargs['colorbar_label'])
else:
plt.colorbar(im, label='Power (dB/Hz)')
plt.xlabel('Time (s)')
plt.ylabel('Frequency (Hz)')
return plt.gcf()
示例2: test_nonuniformimage_setcmap
# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_cmap [as 别名]
def test_nonuniformimage_setcmap():
ax = plt.gca()
im = NonUniformImage(ax)
im.set_cmap('Blues')
示例3: cross_wavelet
# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_cmap [as 别名]
def cross_wavelet(self, signal_1, signal_2, mother='morlet', plot=True):
signal_1 = (signal_1 - signal_1.mean()) / signal_1.std() # Normalizing
signal_2 = (signal_2 - signal_2.mean()) / signal_2.std() # Normalizing
W12, cross_coi, freq, signif = wavelet.xwt(signal_1, signal_2, self.period, dj=1/100, s0=-1, J=-1,
significance_level=0.95, wavelet=mother,
normalize=True)
cross_power = np.abs(W12)**2
cross_sig = np.ones([1, signal_1.size]) * signif[:, None]
cross_sig = cross_power / cross_sig
cross_period = 1/freq
WCT, aWCT, corr_coi, freq, sig = wavelet.wct(signal_1, signal_2, self.period, dj=1/100, s0=-1, J=-1,
sig=False,significance_level=0.95, wavelet=mother,
normalize=True)
cor_sig = np.ones([1, signal_1.size]) * sig[:, None]
cor_sig = np.abs(WCT) / cor_sig
cor_period = 1/freq
angle = 0.5 * np.pi - aWCT
u, v = np.cos(angle), np.sin(angle)
t1 = np.linspace(0,self.period*signal_1.size,signal_1.size)
## indices for stuff
idx = self.find_closest(cor_period,corr_coi.max())
## Into minutes
t1 /= 60
cross_period /= 60
cor_period /= 60
cross_coi /= 60
corr_coi /= 60
fig1, ax1 = plt.subplots(nrows=1,ncols=1, sharex=True, sharey=True, figsize=(12,12))
extent_cross = [t1.min(),t1.max(),0,max(cross_period)]
extent_corr = [t1.min(),t1.max(),0,max(cor_period)]
im1 = NonUniformImage(ax1, interpolation='nearest', extent=extent_cross)
im1.set_cmap('cubehelix')
im1.set_data(t1, cross_period[:idx], cross_power[:idx,:])
ax1.images.append(im1)
ax1.contour(t1, cross_period[:idx], cross_sig[:idx,:], [-99, 1], colors='k', linewidths=2, extent=extent_cross)
ax1.fill(np.concatenate([t1, t1[-1:]+self.period, t1[-1:]+self.period,t1[:1]-self.period, t1[:1]-self.period]),
(np.concatenate([cross_coi,[1e-9], cross_period[-1:], cross_period[-1:], [1e-9]])),
'k', alpha=0.3,hatch='x')
ax1.set_title('Cross-Wavelet')
# ax1.quiver(t1[::3], cross_period[::3], u[::3, ::3],
# v[::3, ::3], units='width', angles='uv', pivot='mid',
# linewidth=1.5, edgecolor='k', headwidth=10, headlength=10,
# headaxislength=5, minshaft=2, minlength=5)
ax1.set_ylim(([min(cross_period), cross_period[idx]]))
ax1.set_xlim(t1.min(),t1.max())
fig2, ax2 = plt.subplots(nrows=1,ncols=1, sharex=True, sharey=True, figsize=(12,12))
fig2.subplots_adjust(right=0.8)
cbar_ax_1 = fig2.add_axes([0.85, 0.05, 0.05, 0.35])
im2 = NonUniformImage(ax2, interpolation='nearest', extent=extent_corr)
im2.set_cmap('cubehelix')
im2.set_data(t1, cor_period[:idx], np.log10(WCT[:idx,:]))
ax2.images.append(im2)
ax2.contour(t1, cor_period[:idx], cor_sig[:idx,:], [-99, 1], colors='k', linewidths=2, extent=extent_corr)
ax2.fill(np.concatenate([t1, t1[-1:]+self.period, t1[-1:]+self.period,t1[:1]-self.period, t1[:1]-self.period]),
(np.concatenate([corr_coi,[1e-9], cor_period[-1:], cor_period[-1:], [1e-9]])),
'k', alpha=0.3,hatch='x')
ax2.set_title('Cross-Correlation')
# ax2.quiver(t1[::3], cor_period[::3], u[::3,::3], v[::3,::3],
# units='height', angles='uv', pivot='mid',linewidth=1.5, edgecolor='k',
# headwidth=10, headlength=10, headaxislength=5, minshaft=2, minlength=5)
ax2.set_ylim(([min(cor_period), cor_period[idx]]))
ax2.set_xlim(t1.min(),t1.max())
fig2.colorbar(im2, cax=cbar_ax_1)
plt.show()
plt.figure(figsize=(12,12))
im3= plt.imshow(np.rad2deg(aWCT), origin='lower',interpolation='nearest', cmap='seismic', extent=extent_corr)
plt.fill(np.concatenate([t1, t1[-1:]+self.period, t1[-1:]+self.period,t1[:1]-self.period, t1[:1]-self.period]),
(np.concatenate([corr_coi,[1e-9], cor_period[-1:], cor_period[-1:], [1e-9]])),
'k', alpha=0.3,hatch='x')
plt.ylim(([min(cor_period), cor_period[idx]]))
plt.xlim(t1.min(),t1.max())
plt.colorbar(im3)
plt.show()
return
示例4: single_plot
# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_cmap [as 别名]
def single_plot(data, x, y, axes=None, beta=None, cbar_label='',
cmap=plt.get_cmap('RdBu'), vmin=None, vmax=None,
phase_speeds=True, manual_locations=False, **kwargs):
"""
Plot a single frame Time-Distance Diagram on physical axes.
This function uses mpl NonUniformImage to plot a image using x and y arrays,
it will also optionally over plot in contours beta lines.
Parameters
----------
data: np.ndarray
The 2D image to plot
x: np.ndarray
The x coordinates
y: np.ndarray
The y coordinates
axes: matplotlib axes instance [*optional*]
The axes to plot the data on, if None, use plt.gca().
beta: np.ndarray [*optional*]
The array to contour over the top, default to none.
cbar_label: string [*optional*]
The title label for the colour bar, default to none.
cmap: A matplotlib colour map instance [*optional*]
The colourmap to use, default to 'RdBu'
vmin: float [*optional*]
The min scaling for the image, default to the image limits.
vmax: float [*optional*]
The max scaling for the image, default to the image limits.
phase_speeds : bool
Add phase speed lines to the plot
manual_locations : bool
Array for clabel locations.
Returns
-------
None
"""
if axes is None:
axes = plt.gca()
x = x[:xxlim]
data = data[:,:xxlim]
im = NonUniformImage(axes,interpolation='nearest',
extent=[x.min(),x.max(),y.min(),y.max()],rasterized=False)
im.set_cmap(cmap)
if vmin is None and vmax is None:
lim = np.max([np.nanmax(data),
np.abs(np.nanmin(data))])
im.set_clim(vmax=lim,vmin=-lim)
else:
im.set_clim(vmax=vmax,vmin=vmin)
im.set_data(x,y,data)
im.set_interpolation('nearest')
axes.images.append(im)
axes.set_xlim(x.min(),x.max())
axes.set_ylim(y.min(),y.max())
cax0 = make_axes_locatable(axes).append_axes("right", size="5%", pad=0.05)
cbar0 = plt.colorbar(im, cax=cax0, ticks=mpl.ticker.MaxNLocator(7))
cbar0.set_label(cbar_label)
cbar0.solids.set_edgecolor("face")
kwergs = {'levels': [1., 1/3., 1/5., 1/10., 1/20.]}
kwergs.update(kwargs)
if beta is not None:
ct = axes.contour(x,y,beta[:,:xxlim],colors=['k'], **kwergs)
plt.clabel(ct,fontsize=14,inline_spacing=3, manual=manual_locations,
fmt=mpl.ticker.FuncFormatter(betaswap))
axes.set_xlabel("Time [s]")
axes.set_ylabel("Height [Mm]")
示例5: wavelet
# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_cmap [as 别名]
def wavelet(self, signal, mother='morlet', plot=True):
"""
Takes a 1D signal and perfroms a continous wavelet transform.
Parameters
----------
time: ndarray
The 1D time series for the data
data: ndarray
The actual 1D data
mother: string
The name of the family. Acceptable values are Paul, Morlet, DOG, Mexican_hat
plot: bool
If True, will return a plot of the result.
Returns
-------
Examples
--------
"""
sig_level = 0.95
std2 = signal.std() ** 2
signal_orig = signal[:]
signal = (signal - signal.mean())/ signal.std()
t1 = np.linspace(0,self.period*signal.size,signal.size)
wave, scales, freqs, coi, fft, fftfreqs = wavelet.cwt(signal,
self.period,
wavelet=mother, dj=1/100)
power = (np.abs(wave)) ** 2
period = 1/freqs
# alpha, _, _ = wavelet.ar1(signal)
alpha = 0.0
## (variance=1 for the normalized SST)
signif, fft_theor = wavelet.significance(1.0, self.period, scales, 0, alpha,
significance_level=sig_level, wavelet=mother)
sig95 = np.ones([1, signal.size]) * signif[:, None]
sig95 = power / sig95
glbl_power = std2 * power.mean(axis=1)
dof = signal.size - scales
glbl_signif, tmp = wavelet.significance(std2, self.period, scales, 1, alpha,
significance_level=sig_level, dof=dof, wavelet=mother)
## indices for stuff
idx = self.find_closest(period,coi.max())
## Into minutes
t1 /= 60
period /= 60
coi /= 60
if plot:
plt.figure(figsize=(12,12))
ax = plt.axes([0.1, 0.75, 0.65, 0.2])
ax.plot(t1, signal_orig-signal_orig.mean(), 'k', linewidth=1.5)
extent = [t1.min(),t1.max(),0,max(period)]
bx = plt.axes([0.1, 0.1, 0.65, 0.55], sharex=ax)
im = NonUniformImage(bx, interpolation='nearest', extent=extent)
im.set_cmap('cubehelix')
im.set_data(t1, period[:idx], power[:idx,:])
bx.images.append(im)
bx.contour(t1, period[:idx], sig95[:idx,:], [-99,1], colors='w', linewidths=2, extent=extent)
bx.fill(np.concatenate([t1, t1[-1:]+self.period, t1[-1:]+self.period,t1[:1]-self.period, t1[:1]-self.period]),
(np.concatenate([coi,[1e-9], period[-1:], period[-1:], [1e-9]])),
'k', alpha=0.3,hatch='x', zorder=100)
bx.set_xlim(t1.min(),t1.max())
cx = plt.axes([0.77, 0.1, 0.2, 0.55], sharey=bx)
cx.plot(glbl_signif[:idx], period[:idx], 'k--')
cx.plot(glbl_power[:idx], period[:idx], 'k-', linewidth=1.5)
cx.set_ylim(([min(period), period[idx]]))
plt.setp(cx.get_yticklabels(), visible=False)
plt.show()
return wave, scales, freqs, coi, power