本文整理汇总了Python中matplotlib.pyplot.figure函数的典型用法代码示例。如果您正苦于以下问题:Python figure函数的具体用法?Python figure怎么用?Python figure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了figure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
def show(self, rescale=True, ax=None):
"""Visualization of a design matrix
Parameters
----------
rescale: bool, optional
rescale columns magnitude for visualization or not
ax: axis handle, optional
Handle to axis onto which we will draw design matrix
Returns
-------
ax: axis handle
"""
import matplotlib.pyplot as plt
# normalize the values per column for better visualization
x = self.matrix.copy()
if rescale:
x = x / np.sqrt(np.sum(x ** 2, 0))
if ax is None:
plt.figure()
ax = plt.subplot(1, 1, 1)
ax.imshow(x, interpolation='Nearest', aspect='auto')
ax.set_label('conditions')
ax.set_ylabel('scan number')
if self.names is not None:
ax.set_xticks(range(len(self.names)))
ax.set_xticklabels(self.names, rotation=60, ha='right')
return ax
示例2: draw_ranges_for_parameters
def draw_ranges_for_parameters(data, title='', save_path='./pictures/'):
parameters = data.columns.values.tolist()
# remove flight name parameter
for idx, parameter in enumerate(parameters):
if parameter == 'flight_name':
del parameters[idx]
flight_names = np.unique(data['flight_name'])
print len(flight_names)
for parameter in parameters:
plt.figure()
axis = plt.gca()
# ax.set_xticks(numpy.arange(0,1,0.1))
axis.set_yticks(flight_names)
axis.tick_params(labelright=True)
axis.set_ylim([94., 130.])
plt.grid()
plt.title(title)
plt.xlabel(parameter)
plt.ylabel('flight name')
colors = iter(cm.rainbow(np.linspace(0, 1,len(flight_names))))
for flight in flight_names:
temp = data[data.flight_name == flight][parameter]
plt.plot([np.min(temp), np.max(temp)], [flight, flight], c=next(colors), linewidth=2.0)
plt.savefig(save_path+title+'_'+parameter+'.jpg')
plt.close()
示例3: plot_predict_is
def plot_predict_is(self,h=5,**kwargs):
""" Plots forecasts with the estimated model against data
(Simulated prediction with data)
Parameters
----------
h : int (default : 5)
How many steps to forecast
Returns
----------
- Plot of the forecast against data
"""
figsize = kwargs.get('figsize',(10,7))
plt.figure(figsize=figsize)
date_index = self.index[-h:]
predictions = self.predict_is(h)
data = self.data[-h:]
t_params = self.transform_z()
plt.plot(date_index,np.abs(data-t_params[-1]),label='Data')
plt.plot(date_index,predictions,label='Predictions',c='black')
plt.title(self.data_name)
plt.legend(loc=2)
plt.show()
示例4: plot_scenario
def plot_scenario(strategies, names, scenario_id=1):
probabilities = get_scenario(scenario_id)
plt.figure(figsize=(6, 4.5))
ax = plt.subplot(111)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.yticks(fontsize=14)
plt.xticks(fontsize=14)
plt.xlim((0, 1300))
# Remove the tick marks; they are unnecessary with the tick lines we just plotted.
plt.tick_params(axis="both", which="both", bottom="on", top="off",
labelbottom="on", left="off", right="off", labelleft="on")
for rank, (strategy, name) in enumerate(zip(strategies, names)):
plot_strategy(probabilities, strategy, name, rank)
plt.title("Bandits: " + str(probabilities), fontweight='bold')
plt.xlabel('Number of Trials', fontsize=14)
plt.ylabel('Cumulative Regret', fontsize=14)
plt.legend(names)
plt.show()
示例5: plotResults
def plotResults(datasetName, sampleSizes, foldsSet, cvScalings, sampleMethods, fileNameSuffix):
"""
Plots the errors for a particular dataset on a bar graph.
"""
for k in range(len(sampleMethods)):
outfileName = outputDir + datasetName + sampleMethods[k] + fileNameSuffix + ".npz"
data = numpy.load(outfileName)
errors = data["arr_0"]
meanMeasures = numpy.mean(errors, 0)
for i in range(sampleSizes.shape[0]):
plt.figure(k*len(sampleMethods) + i)
plt.title("n="+str(sampleSizes[i]) + " " + sampleMethods[k])
for j in range(errors.shape[3]):
plt.plot(foldsSet, meanMeasures[i, :, j])
plt.xlabel("Folds")
plt.ylabel('Error')
labels = ["VFCV", "PenVF+"]
labels.extend(["VFP s=" + str(x) for x in cvScalings])
plt.legend(tuple(labels))
plt.show()
示例6: test_get_obs
def test_get_obs(self):
plt.figure()
ant_sigs = antennas.antennas_signal(self.ants, self.ant_models, self.sources, self.rad.timebase)
rad_sig_full = self.rad.sampled_signal(ant_sigs[0, :], 0)
obs_full = self.rad.get_full_obs(ant_sigs, self.utc_date, self.config)
ant_sigs_simp = antennas.antennas_simplified_signal(self.ants, self.ant_models, self.sources, self.rad.baseband_timebase, self.rad.int_freq)
obs_simp = self.rad.get_simplified_obs(ant_sigs_simp, self.utc_date, self.config)
freqs, spec_full_before_obs = spectrum.plotSpectrum(rad_sig_full, self.rad.ref_freq, label='full_before_obs_obj', c='blue')
freqs, spec_full = spectrum.plotSpectrum(obs_full.get_antenna(1), self.rad.ref_freq, label='full', c='cyan')
freqs, spec_simp = spectrum.plotSpectrum(obs_simp.get_antenna(1), self.rad.ref_freq, label='simp', c='red')
plt.legend()
self.assertTrue((spec_full_before_obs == spec_full).all(), True)
plt.figure()
plt.plot(freqs, (spec_simp-spec_full)/spec_full)
plt.show()
print len(obs_full.get_antenna(1)), obs_full.get_antenna(1).mean()
print len(obs_simp.get_antenna(1)), obs_simp.get_antenna(1).mean()
示例7: plotTestData
def plotTestData(tree):
plt.figure()
plt.axis([0,1,0,1])
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.title("Green: Class1, Red: Class2, Blue: Class3, Yellow: Class4")
for value in class1:
plt.plot(value[0],value[1],'go')
plt.hold(True)
for value in class2:
plt.plot(value[0],value[1],'ro')
plt.hold(True)
for value in class3:
plt.plot(value[0],value[1],'bo')
plt.hold(True)
for value in class4:
plt.plot(value[0],value[1],'yo')
plotRegion(tree)
for value in classPlot1:
plt.plot(value[0],value[1],'g.',ms=3.0)
plt.hold(True)
for value in classPlot2:
plt.plot(value[0],value[1],'r.', ms=3.0)
plt.hold(True)
for value in classPlot3:
plt.plot(value[0],value[1],'b.', ms=3.0)
plt.hold(True)
for value in classPlot4:
plt.plot(value[0],value[1],'y.', ms=3.0)
plt.grid(True)
plt.show()
示例8: regress_show4
def regress_show4( yEv, yEv_calc, disp = True, graph = True, plt_title = None, ms_sz = None):
# if the output is a vector and the original is a metrix,
# the output is translated to a matrix.
r_sqr, RMSE, MAE, DAE = estimate_accuracy4( yEv, yEv_calc, disp = disp)
if graph:
#plt.scatter( yEv.tolist(), yEv_calc.tolist())
plt.figure()
if ms_sz is None:
ms_sz = max(min( 6000 / yEv.shape[0], 8), 3)
# plt.plot( yEv.tolist(), yEv_calc.tolist(), '.', ms = ms_sz) # Change ms
plt.scatter( yEv.tolist(), yEv_calc.tolist(), s = ms_sz)
ax = plt.gca()
lims = [
np.min([ax.get_xlim(), ax.get_ylim()]), # min of both axes
np.max([ax.get_xlim(), ax.get_ylim()]), # max of both axes
]
# now plot both limits against eachother
#ax.plot(lims, lims, 'k-', alpha=0.75, zorder=0)
ax.plot(lims, lims, '-', color = 'pink')
plt.xlabel('Experiment')
plt.ylabel('Prediction')
if plt_title is None:
plt.title( '$r^2$={0:.1e}, RMSE={1:.1e}, MAE={2:.1e}, MedAE={3:.1e}'.format( r_sqr, RMSE, MAE, DAE))
elif plt_title != "":
plt.title( plt_title)
# plt.show()
return r_sqr, RMSE, MAE, DAE
示例9: cv_show
def cv_show( yEv, yEv_calc, disp = True, graph = True, grid_std = None):
# if the output is a vector and the original is a metrix,
# the output is translated to a matrix.
if len( np.shape(yEv_calc)) == 1:
yEv_calc = np.mat( yEv_calc).T
if len( np.shape(yEv)) == 1:
yEv = np.mat( yEv).T
r_sqr, RMSE = jchem.estimate_accuracy( yEv, yEv_calc, disp = disp)
if graph:
#plt.scatter( yEv.tolist(), yEv_calc.tolist())
plt.figure()
ms_sz = max(min( 4000 / yEv.shape[0], 8), 1)
plt.plot( yEv.tolist(), yEv_calc.tolist(), '.', ms = ms_sz) # Change ms
ax = plt.gca()
lims = [
np.min([ax.get_xlim(), ax.get_ylim()]), # min of both axes
np.max([ax.get_xlim(), ax.get_ylim()]), # max of both axes
]
# now plot both limits against eachother
#ax.plot(lims, lims, 'k-', alpha=0.75, zorder=0)
ax.plot(lims, lims, '-', color = 'pink')
plt.xlabel('Experiment')
plt.ylabel('Prediction')
if grid_std:
plt.title( '($r^2$, std) = ({0:.2e}, {1:.2e}), RMSE = {2:.2e}'.format( r_sqr, grid_std, RMSE))
else:
plt.title( '$r^2$ = {0:.2e}, RMSE = {1:.2e}'.format( r_sqr, RMSE))
plt.show()
return r_sqr, RMSE
示例10: make_fish
def make_fish(zoom=False):
plt.close(1)
plt.figure(1, figsize=(6, 4))
plt.plot(plot_limits['pitch'], plot_limits['rolldev'], '-g', lw=3)
plt.plot(plot_limits['pitch'], -plot_limits['rolldev'], '-g', lw=3)
plt.plot(pitch.midvals, roll.midvals, '.b', ms=1, alpha=0.7)
p, r = make_ellipse() # pitch, off nominal roll
plt.plot(p, r, '-c', lw=2)
gf = -0.08 # Fudge on pitch value for illustrative purposes
plt.plot(greta['pitch'] + gf, -greta['roll'], '.r', ms=1, alpha=0.7)
plt.plot(greta['pitch'][-1] + gf, -greta['roll'][-1], 'xr', ms=10, mew=2)
if zoom:
plt.xlim(46.3, 56.1)
plt.ylim(4.1, 7.3)
else:
plt.ylim(-22, 22)
plt.xlim(40, 180)
plt.xlabel('Sun pitch angle (deg)')
plt.ylabel('Sun off-nominal roll angle (deg)')
plt.title('Mission off-nominal roll vs. pitch (5 minute samples)')
plt.grid()
plt.tight_layout()
plt.savefig('fish{}.png'.format('_zoom' if zoom else ''))
示例11: make_entity_plot
def make_entity_plot(filename, title, fixed_noip, fixed_ip, dynamic_noip, dynamic_ip):
plt.figure(figsize=(12,5))
plt.title("Settings comparison - " + title)
plt.xlabel('Time (ms)', fontsize=12)
plt.xlim([0,62000])
x = 0
barwidth = 0.5
bargroupspacing = 1.5
fixed_noip_mean,fixed_noip_conf = conf_stats(fixed_noip)
fixed_ip_mean,fixed_ip_conf = conf_stats(fixed_ip)
dynamic_noip_mean,dynamic_noip_conf = conf_stats(dynamic_noip)
dynamic_ip_mean,dynamic_ip_conf = conf_stats(dynamic_ip)
values = [fixed_noip_mean,fixed_ip_mean,dynamic_noip_mean, dynamic_ip_mean]
errs = [fixed_noip_conf,fixed_ip_conf,dynamic_noip_conf, dynamic_ip_conf]
y_pos = numpy.arange(len(values))
plt.barh(y_pos, values, xerr=errs, align='center', color=['r', 'b', 'r', 'b'], ecolor='black', alpha=0.7)
plt.yticks(y_pos, ["Fixed | no I.P.", "Fixed | I.P.", "Dynamic | no I.P.", "Dynamic | I.P."])
plt.savefig(output_file(filename))
plt.clf()
示例12: delta
def delta():
beta = 0.99
N = 1000
u = lambda c: np.sqrt(c)
W = np.linspace(0,1,N)
X, Y = np.meshgrid(W,W)
Wdiff = (X-Y).T
index = Wdiff <0
Wdiff[index] = 0
util_grid = u(Wdiff)
util_grid[index] = -10**10
Vprime = np.zeros((N,1))
delta = np.ones(1)
tol = 10**-9
it = 0
max_iter = 500
while (delta[-1] >= tol) and (it < max_iter):
V = Vprime
it += 1;
val = util_grid + beta*V.T
Vprime = np.amax(val, axis = 1)
Vprime = Vprime.reshape((N,1))
delta = np.append(delta,np.dot((Vprime-V).T,Vprime-V))
plt.figure()
plt.plot(delta[1:])
plt.ylabel(r'$\delta_k$')
plt.xlabel('iteration')
plt.savefig('convergence.pdf')
plt.clf()
示例13: blue_sideband_thermal_tester
def blue_sideband_thermal_tester():
#BSB sideband = +1
import matplotlib.pyplot as plt
dataobj = ReadData('2014Jun19',experiment = 'RabiFlopping' )
data = dataobj.get_data('1212_15')
sideband = 1
trap_freq = 2.57
nbar_init= .3 #default 20.
rabi = RabiFlop(data)
rabi.setData(data)
f_rabi = thermal_tester() #f_rabi is the same on same set of data
print("f_rabi from thermal tester is :"+str(f_rabi))
initial_guess = {'nbar':nbar_init, 'f_rabi':f_rabi, #same as that of thermal tester
'delta':0.0, 'delta_fluctuations':0.,
'trap_freq':trap_freq, 'sideband':sideband, 'nmax':1000,
'angle': 50./360.*2*np.pi,
'rabi_type':'thermal','eta': 0.04 #rabi.guess_eta()#0.05
}
fit_params = {}
#Put it in the fit params format
for key in initial_guess.keys():
fit_params[key] = (False, False, initial_guess[key]) # fixed most of the parameters
fit_params['nbar'] = (False, False, initial_guess['nbar'])
fit_params['angle'] = (True, False, initial_guess['angle'])
#fit_params['delta'] = (True, False, initial_guess['delta']) #we decided to fix delta
rabi.setUserParameters(fit_params)
x,y = rabi.fit()
plt.figure()
plt.plot(data[:,0], data[:,1],'o') # plotting raw data : excitation probability versus time
plt.plot(x,y) #plotting the fit
nbar = rabi.get_parameter_value('nbar') # rabi frequency in Hz
angle= rabi.get_parameter_value('angle')
print ('nbar: {}'.format(nbar))
print ('{} radians = {} degrees'.format(str(angle), str(angle/(2*np.pi)*360)))
示例14: thermal_tester
def thermal_tester():
import matplotlib.pyplot as plt
dataobj = ReadData('2014Jun19',experiment = 'RabiFlopping' )
car_data = dataobj.get_data('1219_57')
sideband = 0
trap_freq = 2.57
nbar_init= 0.1 #default 20.
carrier_rabi = RabiFlop(car_data)
initial_guess = {'nbar':nbar_init, 'f_rabi':carrier_rabi.guess_f_rabi(), #changing inital guess for rabi frequency to 1/2 max
'delta':0., 'delta_fluctuations':0.,
'trap_freq':trap_freq, 'sideband':sideband, 'nmax':1000,
'angle':10./360.*2*np.pi , 'rabi_type':'thermal'
,'eta': 0.05 }
fit_params = {}
#Put it in the fit params format
for key in initial_guess.keys():
fit_params[key] = (False, False, initial_guess[key]) # fix most of the parameters
fit_params['f_rabi'] = (True, False, initial_guess['f_rabi']) # fit for the rabi frequency
carrier_rabi.setUserParameters(fit_params)
x,y = carrier_rabi.fit()
plt.figure()
plt.plot(car_data[:,0], car_data[:,1],'o') # plotting raw data : excitation probability versus time
plt.plot(x,y) #plotting the fit
# Note: Only get_parameter_value returns the user_guess. Use get_parameter_info for autofit result.
f_rabi = carrier_rabi.get_parameter_info()['f_rabi'][2][2] #autofit result (rabi frequency in Hz)
return f_rabi
示例15: plot_data
def plot_data(kx,omega,F,F_R,F_L,K,O):
#plt.figure(4)
#plt.imshow(K,extent=[omega[0],omega[-1],kx[0],kx[-1]],\
# interpolation = "nearest", aspect = "auto")
#plt.xlabel('KX')
#plt.colorbar()
#plt.figure(5)
#plt.imshow(O,extent =[omega[0],omega[-1],kx[0],kx[-1]],interpolation="nearest", aspect="auto")
#plt.xlabel('omega')
#plt.colorbar()
plt.figure(6)
pylab.subplot(1,2,1)
plt.imshow(abs(F_R), extent= [omega[0],omega[-1],kx[0],kx[-1]], interpolation= "nearest", aspect = "auto")
plt.xlabel('abs FFT_R')
plt.colorbar()
plt.subplot(1,2,2)
plt.imshow(abs(F_L), extent= [omega[0],omega[-1],kx[0],kx[-1]], interpolation= "nearest", aspect = "auto")
plt.xlabel('abs FFT_L')
plt.colorbar()
plt.figure(7)
plt.subplot(2,1,1)
plt.imshow(abs(F_L+F_R),extent=[omega[0],omega[-1],kx[0],kx[-1]],interpolation= "nearest", aspect = "auto")
plt.xlabel('abs(F_L+F_R) reconstructed')
plt.colorbar()
pylab.subplot(2,1,2)
plt.imshow(abs(F),extent=[omega[0],omega[-1],kx[0],kx[-1]],interpolation ="nearest",aspect = "auto")
plt.xlabel('FFT of the original data')
plt.colorbar()
#plt.show()
return