本文整理汇总了Python中matplotlib.pyplot.cla函数的典型用法代码示例。如果您正苦于以下问题:Python cla函数的具体用法?Python cla怎么用?Python cla使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cla函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: graph_ROC
def graph_ROC(max_ACC, TP, FP, name="STD"):
aTP = np.vstack(TP)
n = len(TP)
mean_TP = np.mean(aTP, axis=0)
stderr_TP = np.std(aTP, axis=0) / (n ** 0.5)
var_TP = np.var(aTP, axis=0)
max_TP = mean_TP + 3 * stderr_TP
min_TP = mean_TP - 3 * stderr_TP
# sTP = sum(TP) / len(TP)
sFP = FP[0]
print len(sFP), len(mean_TP), len(TP[0])
smax_ACC = np.mean(max_ACC)
plt.cla()
plt.clf()
plt.close()
plt.plot(sFP, mean_TP)
plt.fill_between(sFP, min_TP, max_TP, color='black', alpha=0.2)
plt.xlim((0,0.1))
plt.ylim((0,1))
plt.title('ROC Curve (accuracy=%.3f)' % smax_ACC)
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.savefig(r"../scratch/"+name+"_ROC_curve.pdf", bbox_inches='tight')
# Write the data to the file
f = file(r"../scratch/"+name+"_ROC_curve.csv", "w")
f.write("FalsePositive,TruePositive,std_err, var, n\n")
for fp, tp, err, var in zip(sFP, mean_TP, stderr_TP, var_TP):
f.write("%s, %s, %s, %s, %s\n" % (fp, tp, err, var, n))
f.close()
示例2: plot2
def plot2(self,oligodata,name):
for level in oligodata:
valcheck=['z(a)','z(c)','z(g)','z(t)','z(t+a)/z(c+g)']
x=[]
y=[]
maxval=0
for val in oligodata[level]:
if (val not in valcheck) and (oligodata[level][val]>maxval):
maxval-=maxval
maxval+=oligodata[level][val]
if (val not in valcheck):
cval=self.get_C(val[0:int(name[3])-1])
cval=cval+'a+'+cval+'c+'+cval+'g+'+cval+'t'
if (cval not in valcheck):
valcheck.append(val)
valcheck.append(cval)
x.append(oligodata[level][val])
y.append(oligodata[level][cval])
maxval=maxval+0.05*maxval
## print 'maxval=',maxval
plt.plot(x,y,'k+')
plt.plot([-1,maxval],[-1,maxval],'k')
## plt.xlabel('x')
## plt.ylabel('y')
plt.text(maxval/2,maxval-2*float(maxval)/100,r'$S_{'+ level+'}^{'+self.sotype+'}$',va='top',ha='center',fontsize=20)
## plt.legend()
resname=self.inpufile.path+name+'_'+level.rpartition('/')[0]+'-'+level.rpartition('/')[2]+'.pdf'
plt.savefig(resname)
plt.cla()
plt.close()
示例3: run_test
def run_test(name):
basepath = os.path.join('results', name)
if not os.path.exists(basepath):
os.makedirs(basepath)
ctrl = LBSimulationController(TestLDCSim)
ctrl.run(ignore_cmdline=True)
horiz = np.loadtxt('ldc_golden/re400_horiz', skiprows=1)
vert = np.loadtxt('ldc_golden/re400_vert', skiprows=1)
plt.plot(2 * (horiz[:,0] - 0.5), -2 * (horiz[:,1] - 0.5), '.', label='Sheu, Tsai paper')
plt.plot(2 * (vert[:,0] - 0.5), -2 * (vert[:,1] - 0.5), '.', label='Sheu, Tsai paper')
save_output(basepath, MAX_ITERS)
plt.legend(loc='lower right')
plt.gca().yaxis.grid(True)
plt.gca().xaxis.grid(True)
plt.gca().xaxis.grid(True, which='minor')
plt.gca().yaxis.grid(True, which='minor')
plt.title('Lid Driven Cavity, Re = 400')
print os.path.join(basepath, 're400.pdf' )
plt.savefig(os.path.join(basepath, 're400.pdf' ), format='pdf')
plt.clf()
plt.cla()
plt.show()
shutil.rmtree(tmpdir)
示例4: generate_plots
def generate_plots(session, result_dir, output_dir):
ratios = read_ratios(result_dir)
iteration = session.query(func.max(cm2db.RowMember.iteration))
clusters = [r[0] for r in session.query(cm2db.RowMember.cluster).distinct().filter(
cm2db.RowMember.iteration == iteration)]
figure = plt.figure(figsize=(6,3))
for cluster in clusters:
plt.clf()
plt.cla()
genes = [r.row_name.name for r in session.query(cm2db.RowMember).filter(
and_(cm2db.RowMember.cluster == cluster, cm2db.RowMember.iteration == iteration))]
cluster_conds = [c.column_name.name for c in session.query(cm2db.ColumnMember).filter(
and_(cm2db.ColumnMember.cluster == cluster, cm2db.ColumnMember.iteration == iteration))]
all_conds = [c[0] for c in session.query(cm2db.ColumnName.name).distinct()]
non_cluster_conds = [cond for cond in all_conds if not cond in set(cluster_conds)]
cluster_data = ratios.loc[genes, cluster_conds]
non_cluster_data = ratios.loc[genes, non_cluster_conds]
min_value = ratios.min()
max_value = ratios.max()
for gene in genes:
values = [normalize_js(val) for val in cluster_data.loc[gene,:].values]
values += [normalize_js(val) for val in non_cluster_data.loc[gene,:].values]
plt.plot(values)
# plot the "in"/"out" separator line
cut_line = len(cluster_conds)
plt.plot([cut_line, cut_line], [min_value, max_value], color='red',
linestyle='--', linewidth=1)
plt.savefig(os.path.join(output_dir, "exp-%d" % cluster))
plt.close(figure)
示例5: plot_scores
def plot_scores(fn,expa,x,y,xl,yl,title=''):
Persons(expa).plot(plt,x,y)
plt.title('PLS, '+str(len(y))+' samples'+title)
plt.xlabel(xl)
plt.ylabel(yl)
plt.savefig(out_pre+"scores"+fn+".png")
plt.cla()
示例6: vis_detections
def vis_detections(im, class_name, dets, thresh=0.3):
"""Visual debugging of detections."""
import matplotlib.pyplot as plt
im_show = im
if sdha_cfg.channels == 3:
im = im[:, :, (2, 1, 0)]
im_show = im
elif sdha_cfg.channels == 4:
b,g,r,mhi = cv2.split(im)
im_show = cv2.merge([r,g,b])
else:
pass
for i in xrange(np.minimum(10, dets.shape[0])):
bbox = dets[i, :4]
score = dets[i, -1]
if score > thresh:
plt.cla()
plt.imshow(im_show)
plt.gca().add_patch(
plt.Rectangle((bbox[0], bbox[1]),
bbox[2] - bbox[0],
bbox[3] - bbox[1], fill=False,
edgecolor='g', linewidth=3)
)
plt.title('{} {:.3f}'.format(class_name, score))
plt.show()
示例7: _update
def _update(num, data):
nonlocal cmap1, bins, ax
# clear axes, load data to refresh
plt.cla()
data = np.loadtxt(core_dict['DataFolder'] + "/data0.txt", float)
# plots
plt.axvline(x = np.average(data),
color = cmap1(0.5),
ls="--" ,
linewidth=1.7)
plt.hist(data, bins,
alpha=0.6,
normed=1,
facecolor=cmap1(0.8),
label="X ~ Beta(2,5)")
# labels
legend = plt.legend(loc='upper right', framealpha = 1.0)
legend.get_frame().set_linewidth(1)
plt.title(core_dict['PlotTitle'], style='italic')
plt.xlabel('Regret')
plt.ylabel('Frequency')
ax.set_ylim([0,0.2])
示例8: update
def update():
pyplot.cla()
pyplot.axis([0, 255, -128, 128])
pyplot.ylabel("Error (higher means too bright)")
pyplot.xlabel("Ideal colour")
pyplot.grid()
delta = [0, 0, 0]
for n, ideal, measured in pop_with_progress(analyse_colours_video(), 50):
pyplot.draw()
for c in [0, 1, 2]:
ideals[c].append(ideal[c])
delta[c] = measured[c] - ideal[c]
deltas[c].append(delta[c])
pyplot.plot([ideal[0]], [delta[0]], "rx", [ideal[1]], [delta[1]], "gx", [ideal[2]], [delta[2]], "bx")
fits = [fit_fn(ideals[n], deltas[n]) for n in [0, 1, 2]]
pyplot.plot(
range(0, 256),
[fits[0](x) for x in range(0, 256)],
"r-",
range(0, 256),
[fits[1](x) for x in range(0, 256)],
"g-",
range(0, 256),
[fits[2](x) for x in range(0, 256)],
"b-",
)
pyplot.draw()
示例9: update
def update(frame_number):
plt.cla()
if map_msg is not None:
for lane in map_msg.hdmap.lane:
draw_lane_boundary(lane, ax, 'b', map_msg.lane_marker)
draw_lane_central(lane, ax, 'r')
for key in map_msg.navigation_path:
x = []
y = []
for point in map_msg.navigation_path[key].path.path_point:
x.append(point.y)
y.append(point.x)
ax.plot(x, y, ls='-', c='g', alpha=0.3)
if planning_msg is not None:
x = []
y = []
for tp in planning_msg.trajectory_point:
x.append(tp.path_point.y)
y.append(tp.path_point.x)
ax.plot(x, y, ls=':', c='r', linewidth=5.0)
ax.axvline(x=0.0, alpha=0.3)
ax.axhline(y=0.0, alpha=0.3)
ax.set_xlim([10, -10])
ax.set_ylim([-10, 200])
y = 10
while y < 200:
ax.plot([10, -10], [y, y], ls='-', c='g', alpha=0.3)
y = y + 10
plt.yticks(np.arange(10, 200, 10))
adc = plt.Circle((0, 0), 0.3, color='r')
plt.gcf().gca().add_artist(adc)
ax.relim()
示例10: plot_session_PSTH
def plot_session_PSTH(self, session, tetrode, experiment=-1, site=-1, cluster = None, sortArray='currentFreq', timeRange = [-0.5, 1], replace=0, lw=3, colorEachCond=None):
sessionObj = self.get_session_obj(session, experiment, site)
sessionDir = sessionObj.ephys_dir()
ephysData, bdata, info = self.load_session_data(session, experiment, site, tetrode, cluster)
eventOnsetTimes = ephysData['events']['stimOn']
spikeTimestamps = ephysData['spikeTimes']
if bdata is not None:
sortArray = bdata[sortArray]
if colorEachCond is None:
colorEachCond = self.get_colours(len(np.unique(sortArray)))
else:
sortArray = []
plotTitle = info['sessionDir']
ephysData = ephyscore.load_ephys(sessionObj.subject, sessionObj.paradigm, sessionDir, tetrode, cluster)
eventOnsetTimes = ephysData['events']['stimOn']
spikeTimestamps = ephysData['spikeTimes']
if replace==1:
plt.cla()
elif replace==2:
plt.sca(ax)
else:
plt.figure()
plot_psth(spikeTimestamps, eventOnsetTimes, sortArray = sortArray, timeRange=timeRange, lw=lw, colorEachCond=colorEachCond, plotLegend=0)
示例11: plot_session_freq_tuning
def plot_session_freq_tuning(self, session, tetrode, experiment = -1, site = -1, cluster = None, sortArray='currentFreq', replace=0, timeRange=[0,0.1]):
if replace:
plt.cla()
else:
plt.figure()
sessionObj = self.get_session_obj(session, experiment, site)
sessionDir = sessionObj.ephys_dir()
ephysData, bdata, info = self.load_session_data(session, experiment, site, tetrode, cluster)
freqEachTrial = bdata[sortArray]
# eventData = self.loader.get_session_events(sessionDir)
# eventOnsetTimes = self.loader.get_event_onset_times(eventData)
# spikeData = self.loader.get_session_spikes(sessionDir, tetrode, cluster)
# spikeTimestamps = spikeData.timestamps
eventOnsetTimes = ephysData['events']['stimOn']
spikeTimestamps = ephysData['spikeTimes']
plotTitle = sessionDir
freqLabels = ["%.1f"%freq for freq in np.unique(freqEachTrial)/1000]
self.one_axis_tc_or_rlf(spikeTimestamps, eventOnsetTimes, freqEachTrial, timeRange=timeRange)
ax = plt.gca()
ax.set_xticks(range(len(freqLabels)))
ax.set_xticklabels(freqLabels, rotation='vertical')
示例12: plot_distribution
def plot_distribution(nx_graph, filename):
"""
Plots the in/out degree distribution of the Graph
:rtype : None
:param nx_graph: nx.Digraph() - Directed NetworkX Graph
:param filename: String - Name of the file to save the plot
"""
in_degrees = nx_graph.in_degree()
in_values = sorted(set(in_degrees.values()))
out_degrees = nx_graph.out_degree()
out_values = sorted(set(out_degrees.values()))
in_hist = [in_degrees.values().count(x) for x in in_values]
out_hist = [out_degrees.values().count(x) for x in out_values]
plt.clf()
plt.cla()
plt.figure()
plt.plot(in_values, in_hist,'ro-') # in-degree
plt.plot(out_values, out_hist,'bv-') # out-degree
# plt.yscale('log')
plt.legend(['In-degree','Out-degree'])
plt.xlabel('Degree')
plt.ylabel('Number of nodes')
plt.title('In-Out Degree Distribution')
plt.savefig(filename + '.png', format='png')
plt.close()
示例13: plot_skus
def plot_skus(data, plot_name, save=True):
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
q = data['q']
p = data['ppr']
flag = data['promo_flag']
np = data['npr']
fig, ax = plt.subplots(figsize=(15,8))
q.plot(ax=ax, grid=True, color='black')
p.plot(ax=ax, secondary_y=True, grid=True, color='red')
np.plot(ax=ax, secondary_y=True, grid=True, color='gray')
flag.plot(ax=ax, secondary_y=True, grid=True, color='blue')
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=2))
ax.set_ylabel(q.name)
ax.right_ax.set_ylabel(p.name)
fig.autofmt_xdate()
ax.legend()
fig.tight_layout()
fig.savefig(plot_name)
plt.close(fig)
plt.cla()
return None
示例14: kinect3DPlotDemo
def kinect3DPlotDemo():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.ion()
plt.show()
openni2.initialize()
dev = openni2.Device.open_any()
ds = dev.create_depth_stream()
ds.start()
while(1):
f = ds.read_frame().get_buffer_as_uint16()
a = np.ndarray((480,640),dtype=np.uint16,buffer=f)
ipts = []
for y in range(180, 300, 20):
for x in range(260, 380, 20):
ipts.append((x, y, a[y][x]))
m = np.matrix(ipts).T
fpts = rwCoordsFromKinect(m) #get real world coordinates
plt.cla()
ax.scatter([pt[0] for pt in fpts], [pt[1] for pt in fpts], [pt[1] for pt in fpts], color='r')
plt.draw()
p = planeFromPts(np.matrix(random.sample(fpts, 3))) #fit a plane to these points
print p
plt.pause(.1)
示例15: run_test
def run_test(name, i):
global RE
RE = reynolds[i]
global MAX_ITERS
MAX_ITERS = max_iters[i]
basepath = os.path.join('results', name, 're%s' % RE)
if not os.path.exists(basepath):
os.makedirs(basepath)
ctrl = LBSimulationController(TestLDCSim, TestLDCGeometry)
ctrl.run()
horiz = np.loadtxt('ldc_golden/vx2d', skiprows=4)
vert = np.loadtxt('ldc_golden/vy2d', skiprows=4)
plt.plot(horiz[:, 0] * 2 - 1, horiz[:, i+1], label='Paper')
plt.plot(vert[:, i+1], 2 * (vert[:, 0] - 0.5), label='Paper')
save_output(basepath)
plt.legend(loc='lower right')
plt.gca().yaxis.grid(True)
plt.gca().xaxis.grid(True)
plt.gca().xaxis.grid(True, which='minor')
plt.gca().yaxis.grid(True, which='minor')
plt.title('Lid Driven Cavity, Re = %s' % RE)
print os.path.join(basepath, 'results.pdf')
plt.savefig(os.path.join(basepath, 'results.pdf'), format='pdf')
plt.clf()
plt.cla()
plt.show()