def plotReachSet_norm1(self, NUM, figname): fig = p.figure() for j in range(n): ax = fig.add_subplot(2,2,j+1 , aspect='equal') ax.set_xlim(0, 4) ax.set_ylim(0, 1) ax.set_xlabel('$x_'+str(j+1)+'$') ax.set_ylabel('$y_'+str(j+1)+'$') for trace in self: for i in [int(floor(k*len(trace.T)/NUM)) for k in range(NUM)]: verts = [(trace.x[i][j] + 1/trace.d_norm1[i][2*j], trace.y[i][j] ), (trace.x[i][j] , trace.y[i][j] - 1/trace.d_norm1[i][2*j+1]), (trace.x[i][j] - 1/trace.d_norm1[i][2*j], trace.y[i][j] ), (trace.x[i][j] , trace.y[i][j] + 1/trace.d_norm1[i][2*j+1])] # poly = Ellipse((trace.x[i][j],trace.y[i][j]), width=trace.d1[i], height=trace.d2[i], angle=trace.theta[i]) poly = Polygon(verts, facecolor='0.8', edgecolor='k') ax.add_artist(poly) poly.set_clip_box(ax.bbox) poly.set_alpha(1) if i==0: poly.set_facecolor('r') else: poly.set_facecolor(p.rand(3)) #for trace in self: #e = Ellipse((trace.x[0][j],trace.y[0][j]), width=trace.d1[0], height=trace.d2[0], angle=trace.theta[0]) #ax.add_artist(e) #e.set_clip_box(ax.bbox) #e.set_alpha(1) #e.set_facecolor('r') #e.set_edgecolor('r') p.savefig(figname)
def plot_category_chart(ax, res, show_legend=True): """Plot stacked bar chart of remapping response categories Arguments: ax -- axis to plot into res -- trends results dictionary Keyword arguments: show_legend -- whether to draw legend """ from matplotlib.patches import Polygon labels = res['mismatch_labels'] N = res['N_mismatch'] x = np.arange(1, N+1) stacked = np.empty((len(CL_LABELS)+1, N), 'd') stacked[0] = 0.0 stacked[-1] = 1.0 cats = res['categories'] for i in xrange(1,len(CL_LABELS)): stacked[i] = stacked[i-1] + cats[CL_LABELS[i-1]] poly_kwargs = dict(aa=True, lw=1.5, alpha=0.85) xloop = np.concatenate((x, x[::-1])) for i in xrange(len(CL_LABELS)): yloop = np.concatenate((stacked[i], stacked[i+1,::-1])) p = Polygon(np.c_[xloop, yloop], fc=CL_COLORS[i], ec=CL_COLORS[i], label=CL_LABELS[i], **poly_kwargs) ax.add_artist(p) p.set_clip_box(ax.bbox) ax.axis([1, N, 0, 1]) ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlabel('Mismatch') ax.set_ylabel('Response Fraction') if show_legend: ax.legend(loc='upper left', bbox_to_anchor=(1.01, 1.0)) return ax