Exemple #1
0
    def plot(self, datastr):
        data = json.loads(unicode(datastr))
        if "data" in data and "graphs" in data["data"]:
            graphdata = data["data"]["graphs"]
            if len(graphdata) < len(self.canvases):
                for i in reversed(range(self.layout.count())):
                    self.layout.itemAt(i).widget().deleteLater()

                self.canvases = []
                self.figures = []
            for maskindex, set in enumerate(graphdata):
                if len(self.canvases) <= maskindex:
                    self.figures.append(plt.figure())
                    canvas = FigureCanvas(self.figures[maskindex])
                    canvas.setParent(self)
                    self.canvases.append(canvas)
                    self.layout.addWidget(self.canvases[maskindex])
                figure = self.figures[maskindex]
                figure.clf()
                figure.set_frameon(False)

                ax = figure.add_subplot(111)
                ax.set_yscale('symlog')
                ax.set_xlabel(set["columnLabels"][0], fontsize=16)
                ax.set_ylabel(set["columnLabels"][1], fontsize=16)
                ax.set_title(set["kind"] + " " + data["data"]['filename'])
                ax.patch.set_alpha(0)

                x = np.array(set["array"][0])[:]
                y = np.array(set["array"][1])[:]
                e = np.array(set["array"][2])[:]
                ppl.plot(ax, x, y, lw=1.0)
                ppl.fill_between(ax, x, y - e, y + e)
                plt.subplots_adjust(bottom=0.2)
                self.canvases[maskindex].draw()
Exemple #2
0
 def plot(self,datastr):
     data=json.loads(unicode(datastr))
     if  "data" in data and "graphs" in data["data"]:
         graphdata= data["data"]["graphs"]
         if len(graphdata)<len(self.canvases):
             for i in reversed(range(self.layout.count())): 
                 self.layout.itemAt(i).widget().deleteLater()
             
             self.canvases=[]
             self.figures=[]
         for maskindex,set in enumerate(graphdata):
             if len(self.canvases)<=maskindex:
                 self.figures.append(plt.figure( ))
                 canvas=FigureCanvas(self.figures[maskindex])
                 canvas.setParent(self)
                 self.canvases.append(canvas)
                 self.layout.addWidget(self.canvases[maskindex])
             figure=self.figures[maskindex]
             figure.clf()
             figure.set_frameon(False)
            
             ax=figure.add_subplot(111)
             ax.set_yscale('symlog')
             ax.set_xlabel(set["columnLabels"][0],fontsize=16)
             ax.set_ylabel(set["columnLabels"][1],fontsize=16)
             ax.set_title( set["kind"]+" "+data["data"]['filename'])
             ax.patch.set_alpha(0)
            
             x=np.array(set["array"][0])[:]
             y=np.array(set["array"][1])[:]
             e=np.array(set["array"][2])[:]
             ppl.plot(ax,x,y,lw=1.0)
             ppl.fill_between(ax,x,y-e,y+e)
             plt.subplots_adjust(bottom=0.2)
             self.canvases[maskindex].draw()
def plot_filling(path,plotfolder,x,y,z,condition,videoname,name):
	'''simple plot filling maker giving count data'''
	fig, ax = plt.subplots(1)
	ppl.fill_between(x, y, facecolor='black', alpha = ALPHASINGLE)
	ppl.fill_between(x, z, facecolor='pink', alpha = ALPHASINGLE)
	ax.set_ylim([0,8])
	ax.set_xlabel('time in video (sec)')
	ax.set_ylabel('Number of times watched')
	ax.set_title('Number of views by a student in condition {0} of the video \n{1}'.format(condition,videoname))
	fig.savefig(os.path.join(path,plotfolder,'count_'+name+'.png'))
	return None
def plot_mult_counts(path,plotfolder,vlogs, subject, conditions, videoname):
	'''plot multiple counts with different summary stats'''
	'''for a paticular course subject, condition, and video'''
	fig, ax = plt.subplots(1)
	#files = []
	counts = []
	for vlog in vlogs:
		for video in vlog.viewage.keys():
			if vlog.condition in conditions and vlog.subject == subject and video == videoname:
				y = vlog.viewage[videoname]
				if sum(y)==0: #only take into account videos that were watched.
					continue
				x = [i/2 for i in range(len(y))]
				ppl.fill_between(x, y, facecolor='black', alpha = ALPHA) #label=str(vlog.filename))
				#files.append(vlog.filename)
				counts.append(y)
	if counts:
		newcounts = zip(*counts)
		quartile25 = [np.percentile(i,25) for i in newcounts]
		quartile50 = [np.percentile(i,50) for i in newcounts]
		quartile75 = [np.percentile(i,75) for i in newcounts]
		ppl.plot(x,quartile25,'-', color = '#f768a1',label = 'Watched by at least 75% of students', linewidth=2, alpha=0.8)
		ppl.plot(x,quartile50,'-', color = '#ae017e',label = 'Watched by at least 50% of students', linewidth=2, alpha=0.7)
		ppl.plot(x,quartile75,'-', color = '#49006a', label = 'Watched by at least 25% of students', linewidth=2, alpha=0.6)
		ax.set_xlabel('time in video (sec)')
		ax.set_ylabel('Number of times watched')
		if len(conditions)==1:
			ax.set_title('Aggregated views of {0} students in condition {1} for video lecture \n "{2}"'.format(str(len(counts)),conditions[0],videoname))
		else:
			ax.set_title('Aggregated views of {0} students and all conditions for video lecture \n "{1}"'.format(str(len(counts)),videoname))
		ax.set_ylim([0,8])
		ppl.legend()
		# p = plt.Rectangle((0, 0), 1, 1, fc="r")
		# ax.legend([p], files)
		fig.savefig(os.path.join(path,plotfolder,'mult_count_'+subject+'_'+str(conditions)+'_'+videoname+'.png'))
	else:
		print "No counts found under conditions {0} for {1} video called {2}".format(conditions,subject,videoname)
	return None
        else:
            spiketimes = []
            thetas = []
        
        ax1.plot(spiketimes,thetas,'yo',label='Spike times')
        ax1.plot(times,mg,'b',label='Mean prediction')
        ax1.set_title('Gaussian Filter')
        ax1.set_ylabel('Signal space')
        ax1.legend()
    
    ax2 = plt.gcf().add_subplot(2,1,2)
    
    ax2.plot(times,sp,'r',label='Signal')
    if sum(sum(spsp)) !=0:
        (tsp,neursp) = np.where(spsp == 1)
        spiketimesp = times[tsp]
        thetasp = [code.neurons[i].theta for i in neursp]
    else:
        spiketimesp = []
        thetasp = []
    
    ax2.plot(times,mp,label='Mean prediction')
    ppl.fill_between(times,mp-np.sqrt(varp),mp+np.sqrt(varp),ax=ax2)
    ax2.plot(spiketimesp,thetasp,'.',label='Spike times')
    ax2.set_ylabel('Signal space')
    ax2.set_xlabel('Time')
    ax2.legend()
    ax2.set_title('Particle Filter')
    
    plt.savefig('filtering.png',dpi=150)
T_mantle_initial = 1800.


T_cmb_initial = T_mantle_initial + T_excess
Tm_low = T_mantle_initial - 100
Tcmb_low = T_cmb_initial - 100
Tm_high = T_mantle_initial + 100
Tcmb_high = T_cmb_initial + 100

t, y_low = mercury.integrate(Tcmb_low, Tm_low, times)
t, y_high = mercury.integrate(Tcmb_high, Tm_high, times)
t, y = mercury.integrate(T_cmb_initial, T_mantle_initial, times)
t = t/1.e9*Julian_year;
c = [ppl.colors.set2[0], ppl.colors.set2[1]]
plt.figure()
ppl.fill_between(t, y_low[:,0], y_high[:,0], color=c[0], label=r'CMB Temperature \pm 100 K')
plt.plot(t, y_low[:,0],'--k')
plt.plot(t, y_high[:,0],'--k')
ppl.fill_between(t, y_low[:,1], y_high[:,1], color=c[1], label=r'Upper Mantle Temperature \pm 100 K')
plt.plot(t, y_low[:,1],'--k')
plt.plot(t, y_high[:,1],'--k')
#mercury.draw()

ppl.plot( t, y[:,0], lw =3, color=c[0], label = 'CMB Temperature')
ppl.plot( t, y[:,0],  '--k',lw=1)
ppl.plot( t, y[:,1],  lw=3, color=c[1], label = 'Upper Mantle Temperature')
ppl.plot( t, y[:,1],  '--k',lw=1)
plt.xlabel('Time [Ga]')
plt.ylabel('Temperature [K]')
plt.title("Thermal Evolution Mercury")
ppl.legend(loc=1)
Exemple #7
0
 else:
     fig, ax2 = ppl.subplots(1)
 times = np.arange(0.0,dt*timewindow,dt)
 if gaussian:    
     if sum(sum(spsg)) !=0:
         (ts,neurs) = np.where(spsg == 1)
         spiketimes = times[ts]
         thetas = [code.neurons[i].theta for i in neurs]
     else:
         spiketimes = []
         thetas = []
     
     l4, = ax1.plot(times,sg,label='True State')
     l2, = ax1.plot(times,mg,label='Posterior Mean')
     l1, = ax1.plot(spiketimes,thetas,'o',label='Observed Spikes')
     l3 = ppl.fill_between(times,mg-stg,mg+stg,ax=ax1,alpha=0.2)
     c1 = l1.get_color()
     c2 = l2.get_color()
     c3 = l3.get_facecolor()
     c4 = l4.get_color()
     ax1.set_title('Gaussian Assumed Density Filter')
     ax1.set_ylabel('Position [cm] (Preferred Stimulus)')
     ax1.set_xlabel('Time [s]')
     ppl.legend(ax1).get_frame().set_alpha(0.6)
 
 
 thetas = [code.neurons[i].theta for i in sptrain]
 ax2.plot(times,s,color=c4,label = 'True Sate')
 ax2.plot(times,m,color=c2,label='Posterior Mean')
 ax2.plot(times[sptimes],thetas,'o',color=c1,label='Observed Spikes')
 ppl.fill_between(times,m-st,m+st,ax=ax2,facecolor=c3,alpha=0.2)
Exemple #8
0
                 parse_dates=True)
table = table.to_period(freq='W')
commits_per_period = table.hash.groupby(level=0).aggregate(len)

dates = [p.start_time.date() for p in commits_per_period.index]
ncommits = np.asarray(commits_per_period.values)
total_commits = np.zeros(ncommits.shape[0])
for i in np.arange(0, ncommits.shape[0]):
    total_commits[i] = np.sum(ncommits[:i])

fn = interp1d(range(len(dates)), total_commits, 'cubic', bounds_error=False)

fig, ax = plt.subplots(1)
fig.set_size_inches((8, 4.5))
x = np.linspace(0, len(dates), 1000)
ppl.fill_between(x, 0, fn(x), color='blue', alpha=0.5)
ax.set_xlim(0, len(dates))
ax.set_ylim(0, max(total_commits) + 0.1 * max(total_commits))
ax.xaxis.set_ticks(np.linspace(0, len(dates) - 1, 8)[1:-1])


def formatter(x, p):
    if x >= len(dates):
        return ''
    return dates[int(x)].strftime('%b %Y')


formatter = FuncFormatter(formatter)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.tick_bottom()
ax.yaxis.tick_left()