def plot(data, fname): plt.clf() width = 10 data = np.array(data) bins = np.arange(0, max(data), step=width) sns.distplot(data, norm_hist=True, kde=True, bins=bins, label='No ones') plt.ylim((0, 0.001)) plt.xlabel('First passage time (ps)') plt.text( 1000, 0.0005, 'MFPT = {0:4.2f} +/- {1:4.2f} ps'.format(data.mean(), 2 * data.std())) plt.savefig(fname, transparanet=True)
def plot_events(real,pred,meta,real_,pred_, label=None): from matplotlib.pylab import plt import random fig,ax = plt.subplots(figsize=(15, .8)) ax.set_title(label) plt.xlim(0,max(meta[1],10)) ax.set_xticks(np.arange(0,max(real[-1][1],10),.1),minor=True) maxsize=20 # random.random()/4 for i in range(min(maxsize,len(pred_))): d = pred_[i] plt.axvspan(d[0], d[1], 0, 0.6,linewidth=0,edgecolor='k',facecolor='#edb4b4', alpha=.6) plt.text((d[1] + d[0]) / 2, 0.2,f'{i}' , horizontalalignment='center', verticalalignment='center') for i in range(min(maxsize,len(pred))): d = pred[i] plt.axvspan(d[0], d[1], 0.0, 0.6,linewidth=0,edgecolor='k',facecolor='#a31f1f', alpha=.6) plt.text((d[1] + d[0]) / 2, 0.2,f'{i}' , horizontalalignment='center', verticalalignment='center') # maxsize=len(real) for i in range(min(maxsize,len(real_))): gt = real_[i] plt.axvspan(gt[0], gt[1], 0.4, 1,linewidth=0,edgecolor='k',facecolor='#d2f57a', alpha=.6) plt.text((gt[1] + gt[0]) / 2, 0.8,f'{i}' , horizontalalignment='center', verticalalignment='center') for i in range(min(maxsize,len(real))): gt = real[i] plt.axvspan(gt[0], gt[1], 0.4, 1,linewidth=0,edgecolor='k',facecolor='#1fa331', alpha=.6) plt.text((gt[1] + gt[0]) / 2, 0.8,f'{i}' , horizontalalignment='center', verticalalignment='center') # plt.grid(True) plt.minorticks_on() ax.set(yticks=[.25,.75], yticklabels=['P','R']) # plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2) plt.show()
def plot_events_with_event_scores(gt_event_scores, detected_event_scores, ground_truth_events, detected_events, label=None): fig, ax = plt.subplots(figsize=(10, 2)) ax.set_title(label) maxsize = 10 maxsize = len(detected_events) for i in range(min(maxsize, len(detected_event_scores))): d = detected_events[i] plt.axvspan(d[0], d[1], 0, 0.5, linewidth=1, edgecolor='k', facecolor='r', alpha=.6) txt = detected_event_scores[i] if type(txt) == int or type(txt) == float: txt = "%g" % round(detected_event_scores[i], 2 if detected_event_scores[i] < 10 else 0) plt.text((d[1] + d[0]) / 2, 0.1 + random.random() / 4, txt, horizontalalignment='center', verticalalignment='center') maxsize = len(ground_truth_events) for i in range(min(maxsize, len(gt_event_scores))): gt = ground_truth_events[i] plt.axvspan(gt[0], gt[1], 0.5, 1, linewidth=1, edgecolor='k', facecolor='g', alpha=.6) txt = gt_event_scores[i] if type(txt) == int or type(txt) == float: txt = "%g" % round(gt_event_scores[i], 2 if gt_event_scores[i] < 10 else 0) plt.text((gt[1] + gt[0]) / 2, 0.6 + random.random() / 4, txt, horizontalalignment='center', verticalalignment='center')
# plt.savefig('result/choice.png') # plt.show() # plt.close() feature_name = ['time','background','body','eye','lefteye','righteye','face','mouth','nose'] dot_data = tree.export_graphviz(clf ,feature_names=feature_name ,class_names=['正常儿童','自闭症儿童'] #,class_names= ['0','1','2'] ,filled=True ,rounded=True ) graph = graphviz.Source(dot_data.replace('helvetica','"Microsoft YaHei"')) graph.render(filename='decision', directory='result_random', format='png', cleanup=True, quiet=True) #保存 #graph.view(filename='result',cleanup=True,quiet=True) eigenvalue = list(zip(feature_name,clf.feature_importances_)) eigenvalue = sorted(eigenvalue, key=lambda x:x[1], reverse=True) value_label = list(zip(*eigenvalue)) from pylab import mpl mpl.rcParams['font.sans-serif'] = ['SimHei'] #设置字体为黑体 plt.title('准确率-%s'%sco) r = plt.bar(range(len(eigenvalue)), value_label[1], color='rgb',tick_label=value_label[0]) totol_eigenvalue = 0 for i,value in zip(r, value_label[1]): totol_eigenvalue += value plt.text(i.get_xy()[0]+i.get_width()/2, i.get_height() + 1/pow(10, len(str(value).split('.')[-1]))/10, '%s'%value, ha='center') plt.legend() plt.savefig('result_random/eigenvalueSort.png') plt.close() #plt.show()
else: weights[ed] = 1 edg.append([edges[l][0],edges[l][1]]) import matplotlib.patches as patches style = "Simple, tail_width=2, head_width=0, head_length=1" kw = dict(arrowstyle=style, color="k") for l in range(len(edges)): # psy = (pos[edges[l][1]][0], 0.01+pos[edges[l][1]][1]) a = patches.FancyArrowPatch(pos[edges[l][0]], pos[edges[l][1]],#psy, connectionstyle="arc3,rad=.43", **kw) ax.add_patch(a) for l in range(len(edg)): we = str(edg[l][0]) + str(edg[l][1]) if(we=='14'): ytext = pos[edges[l][0]][1]-0.04 xtext = (edg[l][0] + edg[l][1]) / 2 -1 elif(we=='24'): ytext = pos[edges[l][0]][1]-0.015 xtext = (edg[l][0] + edg[l][1]) / 2 -1 else: ytext = pos[edges[l][0]][1]-+0.005 xtext = (edg[l][0] + edg[l][1]) / 2 -1.1#pos[edges[l][0]][1] +0.5#- pos[edges[l][0]][1] print(xtext,ytext) plt.text(xtext, ytext, str(weights[we]), fontdict={'size':fs, 'color':'k'}) plt.savefig('illustrationBP.png', bbox_inches='tight', dpi=300) plt.show()