本文整理汇总了Python中matplotlib.cm.rainbow函数的典型用法代码示例。如果您正苦于以下问题:Python rainbow函数的具体用法?Python rainbow怎么用?Python rainbow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rainbow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotPoints3D
def plotPoints3D(self):
colors = cm.rainbow(np.linspace(0, 1, self.cl_cnt))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for c in range(self.cl_cnt):
centroid = self.centroids[c]
x = []
y = []
z = []
cluster_size = len(self.cl_points[c])
#for each point assorted to the cluster
for p in range(cluster_size):
index = self.cl_points[c][p] #index of the point
point = self.points[index]
#print point
x.append(point[0])
y.append(point[1])
z.append(point[2])
clrs = cm.rainbow(np.linspace(0, 1, self.cl_cnt)) #colors
ax.scatter(x, y, z, color=clrs[c], marker='o')
ax.scatter(centroid[0], centroid[1], centroid[2],
color=clrs[c], marker='*', s = 50)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
示例2: LogScaleASP
def LogScaleASP(LRange, Data, unlogged = False, scale = False, tau = 0, D = 0, tauEst = 0, DEst = 0):
"""
Plots log-binned avalanche size probabilities
(if logbin == True, also plots unprocessed data)
"""
plt.figure()
for d in range(len(Data)):
colors = cm.rainbow(np.linspace(0, 1, len(Data)))
if unlogged:
plt.scatter(np.arange(0,len(Data[d][0])),Data[d][0],s = 0.5, label = 'Raw Data')
for i in range(len(Data[d][1])):
#plt.plot(Data[d][1][i][0],Data[d][1][i][1],color = colors[d],label = 'L = ' + str(LRange[d]))
plt.plot(Data[d][1][i][0],Data[d][1][i][1],color = colors[d],label = 'Log-Binned Data')
#plt.plot(np.arange(0,len(Data[d][1][i])),Data[d][1][i],color = colors[d])
if tauEst != 0:
#print 't'
plt.plot([1,10**10],[1,(10**10)**(-tauEst)],linestyle = 'dashed',label = r'$P_N(s;L)\propto s^{-\tau_s}$')
plt.xscale('log')
plt.yscale('log')
#ax = plt.axes()
#ax.grid(True)
plt.xlim((10**0,10**(round(math.log(len(Data[-1][0]),10)) + 1)))
plt.ylim((10**(round(math.log(Data[-1][1][0][1][-1],10)) - 1), 10**0))
plt.xlabel(r'$s$', fontsize = 20)
plt.ylabel(r'$\tilde{P}_N(s;L)$', fontsize = 20)
plt.title(r'$N = 10^9$',fontsize = 25)
plt.legend(prop = {'size':25})
#fig.savefig('Pvs.eps', format = 'eps', dpi = 1000)
logp = [i[1][0] for i in Data]
pscaled = [[p*math.pow(s,tau) for (p,s) in zip(logp[i][1],logp[i][0])] for i in range(len(logp))]
sscaled = [[s/LRange[i]**D for s in logp[i][0]] for i in range(len(logp))]
if scale:
plt.figure()
plt.xscale('log')
plt.yscale('log')
ax = plt.axes()
ax.grid(True)
#plt.xlim((10**0,10**(round(math.log(len(Data[-1][0]),10)) + 1)))
#plt.ylim((10**(-2), 10**0))
plt.ylabel(r'$s^{\tau_s}P(s;L)$',fontsize = 20)
plt.xlabel(r'$s$', fontsize = 20)
for d in range(len(Data)):
colors = cm.rainbow(np.linspace(0, 1, len(Data)))
plt.plot(logp[d][0],pscaled[d],color = colors[d],label = 'L =' + str(LRange[d]))
plt.legend(prop = {'size':15},loc =3)
plt.figure()
ax = plt.axes()
ax.grid(True)
plt.xscale('log')
plt.yscale('log')
#plt.xlim((10**(-6),10**2))
#plt.ylim((10**(-2), 10**0))
plt.ylabel(r'$s^{\tau_s}P(s;L)$',fontsize = 20)
plt.xlabel(r'$s/L^D$', fontsize = 20)
for d in range(len(Data)):
colors = cm.rainbow(np.linspace(0, 1, len(Data)))
plt.plot(sscaled[d][1:],pscaled[d][1:],color = colors[d], label = 'L =' + str(LRange[d]))
plt.legend(prop = {'size':15},loc = 3)
示例3: plot_epam_proton_lcurves
def plot_epam_proton_lcurves(t1, t2):
#convert time to datetime format
dt1 = datetime.datetime.strptime(t1, "%d-%b-%Y %H:%M")
dt2 = datetime.datetime.strptime(t2, "%d-%b-%Y %H:%M")
#set up figure
nl = 3
xc = 255/nl
f, ax = plt.subplots(figsize=(8,4))
#ACE EPAM protons
epam_dates0, epam_lcurve = parse_epam_proton_range(t1, t2)
mxepam = np.amax(epam_lcurve)
l1 = ax.plot(epam_dates0, epam_lcurve[:,0], c = cm.rainbow(1 * xc + 1) ,label='EPAM 0.540 - 0.765 MeV')
l2 = ax.plot(epam_dates0, epam_lcurve[:,1], c = cm.rainbow(3 * xc + 1) ,label='EPAM 0.765 - 1.22 MeV')
l3 = ax.plot(epam_dates0, epam_lcurve[:,2], c = cm.rainbow(5 * xc + 1) ,label='EPAM 1.22 - 4.94 MeV')
#format of tick labels
hrsFmt = mdates.DateFormatter('%d')
ax.xaxis.set_major_formatter(hrsFmt)
ax.set_xlabel("Start Time "+t1+" (UTC)")
ax.set_xlim([dt1, dt2])
ymax = np.max([mxepam, mxepam])
ax.set_ylim(top = ymax)
ax.set_ylim(bottom = 1.e-4)
#auto orientate the labels so they don't overlap
#f.autofmt_xdate()
#set yaxis log
ax.set_yscale('log')
#Axes labels
ax.set_title("ACE EPAM Protons")
ax.set_ylabel('H Intensity $\mathrm{(cm^{2}\,sr\,s\,MeV)^{-1}}$')
#legend
fontP = FontProperties()
fontP.set_size('x-small')
leg = ax.legend(loc='best', prop = fontP, fancybox=True )
leg.get_frame().set_alpha(0.5)
#month
year = dt1.year
month = dt1.month
plt.show()
return None
示例4: _DrawEmpiricalCdf
def _DrawEmpiricalCdf(axis, results):
colors = cm.rainbow(numpy.linspace( # pylint: disable=no-member
1, 0, len(results) + 1))
for (commit, values), color in zip(results, colors):
# Empirical distribution function.
levels = numpy.linspace(0, 1, len(values) + 1)
axis.step(sorted(values) + [max(values)], levels,
label='%s (n=%d)' % (commit, len(values)), color=color)
# Dots denoting the percentiles.
axis.plot(numpy.percentile(values, tuple(p * 100 for p in _PERCENTILES)),
_PERCENTILES, '.', color=color)
axis.set_yticks(_PERCENTILES)
# Vertical lines denoting the medians.
values_per_commit = [values for _, values in results]
medians = tuple(numpy.percentile(values, 50) for values in values_per_commit)
axis.set_xticks(medians, minor=True)
axis.grid(which='minor', axis='x', linestyle='--')
# Axis labels and legend.
#axis.set_xlabel(step.metric_name)
axis.set_ylabel('Cumulative probability')
axis.legend(loc='lower right')
示例5: hists
def hists(dgrp,dfs):
"dgrp = MAIN,DC,EC,SC,MC"
#set up some cosmetics
colors = cm.rainbow(np.linspace(0,1,len(dfs)))
labels = ['h10_%d'%i for i in range(len(dfs))]
ncols=len(dgrp['COLS'])
gs =''
if ncols > 4:
gs = gridspec.GridSpec(2,4)
else:
gs = gridspec.GridSpec(1,ncols)
for icol in np.arange(ncols):
ax=plt.subplot(gs[icol])
col=dgrp['COLS'][icol]
nbins=dgrp['NBINS'][icol]
xmin=dgrp['XMIN'][icol]
xmax=dgrp['XMAX'][icol]
#print 'col=%s:nbins=%d:xmin=%d:xmax%d'%(col,nbins,xmin,xmax)
ax.set_title(col)
ax.set_xlabel(col)
for c,l,df in zip(colors,labels,dfs):
#print df[col]
plt.hist(df[col],nbins,(xmin,xmax), histtype='step',color=c,label=l)
plt.legend(loc=2,prop={'size':8})
示例6: compare_subcarrier_location
def compare_subcarrier_location(alpha, M, K, overlap, oversampling_factor):
import matplotlib.pyplot as plt
import matplotlib.cm as cm
goofy_ordering = False
taps = gfdm_filter_taps('rrc', alpha, M, K, oversampling_factor)
A0 = gfdm_modulation_matrix(taps, M, K, oversampling_factor, group_by_subcarrier=goofy_ordering)
n = np.arange(M * K * oversampling_factor, dtype=np.complex)
colors = iter(cm.rainbow(np.linspace(0, 1, K)))
for k in range(K):
color = next(colors)
f = np.exp(1j * 2 * np.pi * (float(k) / (K * oversampling_factor)) * n)
F = abs(np.fft.fft(f))
fm = np.argmax(F) / M
plt.plot(F, '-.', label=k, color=color)
data = get_zero_f_data(k, K, M)
x0 = gfdm_gr_modulator(data, 'rrc', alpha, M, K, overlap, compat_mode=goofy_ordering) * (2. / K)
f0 = 1. * np.argmax(abs(np.fft.fft(x0))) / M
plt.plot(abs(np.fft.fft(x0)), label='FFT' + str(k), color=color)
xA = A0.dot(get_data_matrix(data, K, group_by_subcarrier=goofy_ordering).flatten()) * (1. / K)
fA = np.argmax(abs(np.fft.fft(xA))) / M
plt.plot(abs(np.fft.fft(xA)), '-', label='matrix' + str(k), color=color)
print fm, fA, f0
plt.legend()
plt.show()
示例7: sendTSNE
def sendTSNE(self, people):
d = self.getData()
if d is None:
return
else:
(X, y) = d
X_pca = PCA(n_components=50).fit_transform(X, X)
tsne = TSNE(n_components=2, init='random', random_state=0)
X_r = tsne.fit_transform(X_pca)
yVals = list(np.unique(y))
colors = cm.rainbow(np.linspace(0, 1, len(yVals)))
# print(yVals)
plt.figure()
for c, i in zip(colors, yVals):
name = "Unknown" if i == -1 else people[i]
plt.scatter(X_r[y == i, 0], X_r[y == i, 1], c=c, label=name)
plt.legend()
imgdata = StringIO.StringIO()
plt.savefig(imgdata, format='png')
imgdata.seek(0)
content = 'data:image/png;base64,' + \
urllib.quote(base64.b64encode(imgdata.buf))
msg = {
"type": "TSNE_DATA",
"content": content
}
self.sendMessage(json.dumps(msg))
示例8: plot_xyt_rotate
def plot_xyt_rotate(s):
xyts = np.fromfile(pdir + 'lcr/rotate.dat')
xs = xyts[1::7][::s]
ys = xyts[2::7][::s]
ts = xyts[6::7][::s]
ds = [1-((x/350)**2 + (y/350)**2)**0.5 for x,y in zip(xs,ys)]
cs = cm.rainbow(ds)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(xs, ys, ts, color=cs, cmap=cm.hsv)
ax.set_xlim3d(0, 300)
ax.set_ylim3d(0, 300)
ax.set_zlim3d(0, 16000)
ax.set_xlabel('area length (m)')
ax.set_ylabel('area width (m)')
ax.set_zlabel('time (min)')
ax.set_xticks([0,100,200,300])
ax.set_yticks([0,100,200,300])
ax.set_zticks([0,4000,8000,12000,16000])
ax.ticklabel_format(axis='z', style='sci', scilimits=(-2,2))
ax.view_init(elev=13., azim=-70)
ax.grid(True)
plt.show()
示例9: plot_dispatch
def plot_dispatch(bus_to_plot):
# plotting: later as multiple pdf with pie-charts and topology?
import numpy as np
import matplotlib as mpl
import matplotlib.cm as cm
plot_data = renew_sources+transformers
# data preparation
x = np.arange(len(timesteps))
y = []
labels = []
for c in plot_data:
if bus_to_plot in c.results['out']:
y.append(c.results['out'][bus_to_plot])
labels.append(c.uid)
# plotting
fig, ax = plt.subplots()
sp = ax.stackplot(x, y,
colors=cm.rainbow(np.linspace(0, 1, len(plot_data))))
proxy = [mpl.patches.Rectangle((0, 0), 0, 0,
facecolor=
pol.get_facecolor()[0]) for pol in sp]
ax.legend(proxy, labels)
ax.grid()
ax.set_xlabel('Timesteps in h')
ax.set_ylabel('Power in MW')
ax.set_title('Dispatch')
示例10: plot_kin_all
def plot_kin_all(expt_dh,imsd_fhs):
fig=plt.figure(figsize=(8,3))
colors=cm.rainbow(np.linspace(0,1,len(imsd_fhs)))
ylimmx=[]
for i,imsd_fh in enumerate(imsd_fhs):
imsd_flt_fh='%s.imsd_flt' % imsd_fh
imsd_flt=pd.read_csv(imsd_flt_fh).set_index('lag time [s]')
params_flt_fh='%s.params_flt' % imsd_fh
params_flt=pd.read_csv(params_flt_fh)
ax1=plt.subplot(131)
ax1=plot_kin(imsd_flt,
params_flt.loc[:,['power law exponent','power law constant']],
ctime='lag $t$',
fit_eqn='power',
smp_ctrl=None,
ylabel='MSD ($\mu m^{2}$)',
color=colors[i],
ymargin=0.2,
ax1=ax1,
label=basename(imsd_flt_fh).split('_replicate', 1)[0].replace('_',' '),
plot_fh=None)
ylimmx.append(np.max(imsd_flt.max()))
ax1.set_ylim([0,np.max(ylimmx)])
ax1.legend(bbox_to_anchor=[1,1,0,0],loc=2)
fig.savefig('%s/plot_flt_%s.pdf' % (expt_dh,dirname(expt_dh)))
示例11: _plot_proto_symbol_space
def _plot_proto_symbol_space(coordinates, target_names, name, args):
# Reduce to 2D so that we can plot it.
coordinates_2d = TSNE().fit_transform(coordinates)
n_samples = coordinates_2d.shape[0]
x = coordinates_2d[:, 0]
y = coordinates_2d[:, 1]
colors = cm.rainbow(np.linspace(0, 1, n_samples))
fig = plt.figure(1)
plt.clf()
ax = fig.add_subplot(111)
dots = []
for idx in xrange(n_samples):
dots.append(ax.plot(x[idx], y[idx], "o", c=colors[idx], markersize=15)[0])
ax.annotate(target_names[idx], xy=(x[idx], y[idx]))
lgd = ax.legend(dots, target_names, ncol=4, numpoints=1, loc='upper center', bbox_to_anchor=(0.5,-0.1))
ax.grid('on')
if args.output_dir is not None:
path = os.path.join(args.output_dir, name + '.pdf')
print('Saved plot to file "%s"' % path)
fig.savefig(path, bbox_extra_artists=(lgd,), bbox_inches='tight')
else:
plt.show()
示例12: pca_3d
def pca_3d(X, component1, component2, component3, class_indices, path, name, data_legend):
C, y, Z = pca(X, class_indices)
colors = cm.rainbow(np.linspace(0, 1, C))
markers = ["o", "v", "8", "s", "p", "*", "h", "H", "+", "x", "D"]
while True:
if C <= len(markers):
break
markers += markers
# Plot PCA of the data
f = plt.figure(figsize=(15, 15))
ax = f.add_subplot(111, projection='3d', axisbg='white')
ax._axis3don = False
for c in range(C):
# select indices belonging to class c:
class_mask = y.A.ravel() == c
xs = Z[class_mask, component1 - 1]
xs = xs.reshape(len(xs)).tolist()[0]
ys = Z[class_mask, component2 - 1]
ys = ys.reshape(len(ys)).tolist()[0]
zs = Z[class_mask, component3 - 1]
zs = zs.reshape(len(zs)).tolist()[0]
ax.scatter(xs, ys, zs, s=20, c=colors[c], marker=markers[c])
# plt.figtext(0.5, 0.93, 'PCA 3D', ha='center', color='black', weight='light', size='large')
f.savefig(path + '/' + name + '.png', dpi=200)
plt.show()
示例13: compute_graph
def compute_graph(players, start, end, resolution, delta, position="allround"):
import collections
import matplotlib.cm as cm
import numpy
q = Archiv.objects.filter(
Q(game__time__gt = start),
Q(game__time__lt = end),
reduce(lambda q1, q2: q1 | q2, map(lambda p: Q(player = p), players))
).order_by('game__time')
start=q[0].game.time
data_plot = dict()
colors = [c for c in cm.rainbow(numpy.linspace(0,1,len(players)))]
for skill_record in q:
if skill_record.player not in data_plot:
data_plot[skill_record.player] = dict()
data_plot[skill_record.player]['color'] = colors.pop()
data_plot[skill_record.player]["skill"] = collections.OrderedDict()
data_plot[skill_record.player]["skill"][start-datetime.timedelta(**{'days': delta})] = 700
#data_plot[skill_record.player]["skill"][resolution(skill_record.game.time)] = skill_record.player.skill(position=position)
if position=="offensiv":
data_plot[skill_record.player]["skill"][resolution(skill_record.game.time)] = compute_skill(skill_record.mu_off,skill_record.sigma_off)
elif position=="defensiv":
data_plot[skill_record.player]["skill"][resolution(skill_record.game.time)] = compute_skill(skill_record.mu_def,skill_record.sigma_def)
else:
data_plot[skill_record.player]["skill"][resolution(skill_record.game.time)] = compute_skill(skill_record.mu,skill_record.sigma)
#colors = cm.rainbow(numpy.linspace(0,1,len(players)))
#print(data_plot)
return {p: ds for p, ds in data_plot.items()}
示例14: fingerprint
def fingerprint(disp_sim_spin = True,n_sim_spins = 13,xrange = [0,20],):
###################
# Add simulated spins #
###################
if disp_sim_spin == True:
HF_par = [hf['C1']['par'],hf['C2']['par'],hf['C3']['par'], hf['C4']['par'], hf['C5']['par'], hf['C6']['par'], hf['C7']['par'], hf['C8']['par'], hf['C9']['par'], hf['C10']['par'], hf['C11']['par'], hf['C12']['par']]
HF_perp = [hf['C1']['perp'],hf['C2']['perp'],hf['C3']['perp'], hf['C4']['perp'], hf['C5']['perp'], hf['C6']['perp'], hf['C7']['perp'], hf['C8']['perp'], hf['C9']['perp'], hf['C10']['perp'], hf['C11']['perp'], hf['C12']['perp']]
#msmp1_f from hdf5 file
# msm1 from hdf5 file
# ZFG g_factor from hdf5file
B_Field = 304.12 # use magnet tools Bz = (msp1_f**2 - msm1_f**2)/(4.*ZFS*g_factor)
tau_lst = np.linspace(0,72e-6,10000)
Mt16 = SC.dyn_dec_signal(HF_par,HF_perp,B_Field,16,tau_lst)
FP_signal16 = ((Mt16+1)/2)
## Data location ##
timestamp ='20140419_005744'
if os.name =='posix':
ssro_calib_folder = '//Users//Adriaan//Documents//teamdiamond//data//20140419//111949_AdwinSSRO_SSROCalibration_Hans_sil1'
else:
ssro_calib_folder = 'd:\\measuring\\data\\20140419\\111949_AdwinSSRO_SSROCalibration_Hans_sil1'
a, folder = load_mult_dat(timestamp, number_of_msmts = 140, ssro_calib_folder=ssro_calib_folder)
###############
## Plotting ###
###############
fig = a.default_fig(figsize=(35,5))
ax = a.default_ax(fig)
# ax.set_xlim(15.0,15.5)
ax.set_xlim(xrange)
start, end = ax.get_xlim()
ax.xaxis.set_ticks(np.arange(start, end, 0.5))
ax.set_ylim(-0.05,1.05)
ax.plot(a.sweep_pts, a.p0, '.-k', lw=0.4,label = 'data') #N = 16
if disp_sim_spin == True:
colors = cm.rainbow(np.linspace(0, 1, n_sim_spins))
for tt in range(n_sim_spins):
ax.plot(tau_lst*1e6, FP_signal16[tt,:] ,'-',lw=.8,label = 'spin' + str(tt+1))#, color = colors[tt])
if False:
tot_signal = np.ones(len(tau_lst))
for tt in range(n_sim_spins):
tot_signal = tot_signal * Mt16[tt,:]
fin_signal = (tot_signal+1)/2.0
ax.plot(tau_lst*1e6, fin_signal,':g',lw=.8,label = 'tot')
plt.legend(loc=4)
print folder
plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.pdf'),
format='pdf')
plt.savefig(os.path.join(folder, str(disp_sim_spin)+'fingerprint.png'),
format='png')
示例15: displayPowerSpectrum
def displayPowerSpectrum(*args):
fig = plt.figure(1)
ax = fig.add_subplot(111)
colors = iter(cm.rainbow(np.linspace(0, 1, len(args))))
for a in args:
dataPowerSpectrum = calculatePowerSpectrum(a.matrix)
n = dataPowerSpectrum.size
xpoly = np.array(range(1,n + 1))
p = ax.plot(xpoly, dataPowerSpectrum, color=next(colors), label=a.name)
Fs = 1/a.data_step[0]
tmp = 1/( Fs/2 * np.linspace(1e-2, 1, int(xpoly.size/6)) )
ax.set_xticks( np.linspace(1,xpoly.size,tmp.size) )
ax.set_xticklabels( ["%.1f" % member for member in tmp] )
del tmp
plt.yscale('log')
plt.grid(linestyle='dotted')
plt.ylabel('Power Spectrum (|f|^2)')
plt.xlabel('Frequency')
plt.legend(loc=3)
plt.show()