function multipeak_plotter(multipeak_matrix,azaz_record,epoch_dividers,hy,conjoined_filename,samples_per_ms)
%there should be three ways to show the asynch event data in this grid:  
%for every trial, put dots to show the asynch event's peak time and size (color shows trial)
%for every trial, put a dot showing how many events there were (x axis is trial)
%put the mean and SD number of events for each history
%for the latter two, it's possible to represent the mean event size on that trial as well, but we'll leave that alone for now

%need to correct for samples_per_ms instead of directly using 10,50,500 below
%may want to get curve fits to the points, get r vals, do hypothesis tests to compare conditions...

number_of_trials=size(multipeak_matrix,2)
floor_of_plot=0;
clrmp=colormap(jet(size(multipeak_matrix,2)));
shapes={'o' 's' 'd' 'v'}
mfc='markerfacecolor';mec='markeredgecolor';ms='markersize'
m_size=16;
figure%(23)

lim=min(min(multipeak_matrix(6:5:end,:)))
%lim=-80 %MUST CHANGE BACK

for j=1:2   %_o is when j==1, _a and _b are when j==2,
    if j==1
        if ~isempty(epoch_dividers),trials_that_were_during_this_epoch=[1:epoch_dividers(1)-.5];else trials_that_were_during_this_epoch=1:number_of_trials;end
		for epoch=1:length(epoch_dividers)+1
            matches=trials_that_were_during_this_epoch
            if ~isempty(matches)
                subplot('position',[0.1 .5-(.5*inv(length(hy))) .3 inv(length(hy))])
                for klm=1:length(matches)
                    good_one=multipeak_matrix(:,matches(klm));
                    good_one=good_one(~isnan(good_one));
                    first_stim=good_one(1);
                    if length(good_one)<2,break,end
                    good_one=good_one(2:end);
                    cutoff=first_stim+azaz_record(matches(klm),1)*samples_per_ms;
                    timez=good_one(3:5:end); valz=good_one(5:5:end);
                    keepers=timez<cutoff;
                    if find(keepers)
                        timez=timez(find(keepers));valz=valz(find(keepers));
                        plot((timez-first_stim)/samples_per_ms,valz,shapes{epoch},mfc,clrmp(matches(klm),:),mec,clrmp(matches(klm),:),ms,m_size),hold on,ylim([lim 0])
                        grid on
                    end
                end
            end
            if epoch==length(epoch_dividers)+1
                set(gcf,'PaperOrientation','landscape'),set(gcf,'PaperPosition',[0.5 0.5 10 7.5])
                %                 set(gca,'xticklabel',get(gca,'xticklabel'),'fontsize',10,'fontweight','bold','fontname','book antiqua')
                xlabel('Time (ms)', 'fontsize',20,'fontname','book antiqua','fontweight','bold')
                ylabel('Event size (pA)', 'fontsize',20,'fontname','book antiqua','fontweight','bold')
                subplot(20,5,11),text(0,0,conjoined_filename,'fontweight','bold','fontsize',6,'fontname','book antiqua'),axis off
			end        
            if length(epoch_dividers)>epoch,trials_that_were_during_this_epoch=[epoch_dividers(epoch)+.5 :epoch_dividers(epoch+1)-.5];
			elseif length(epoch_dividers)==epoch,trials_that_were_during_this_epoch=[epoch_dividers(epoch)+.5:number_of_trials];% mem=number_of_trials,disp('babbyshka')
            end
		end
    elseif j==2  
        for k=1:length(hy)
            if ~isempty(epoch_dividers),trials_that_were_during_this_epoch=[1:epoch_dividers(1)-.5];else trials_that_were_during_this_epoch=1:number_of_trials;end
		    for epoch=1:length(epoch_dividers)+1
%                 bob=azaz_record
%                 slob=trials_that_were_during_this_epoch
%                 fob=hy(k)
                matches_a=trials_that_were_during_this_epoch(find(azaz_record(trials_that_were_during_this_epoch,1)==hy(k)))
                if ~isempty(matches_a)
                    floor_of_plot=(length(hy)-k)/length(hy);
                    subplot('position',[0.4 floor_of_plot .3 inv(length(hy))])
                    for klm=1:length(matches_a)
%                         BBB=matches_a(klm)
                        good_one=multipeak_matrix(:,matches_a(klm));
                        good_one=good_one(~isnan(good_one));
                        first_stim=good_one(1);
	                    if length(good_one)>2
                            good_one=good_one(2:end);
                            early_bound=first_stim+azaz_record(matches_a(klm),1)*samples_per_ms;
                            late_bound=early_bound+azaz_record(1,2)*samples_per_ms;
		%                     azazzzy=good_one(3:5:end)
                            timez=good_one(3:5:end); valz=good_one(5:5:end);
                            keepers=timez>early_bound&timez<late_bound;
                            if find(keepers)
                                timez=timez(find(keepers));valz=valz(find(keepers));
                                plot(((timez-first_stim)/10)-hy(k),valz,shapes{epoch},mfc,clrmp(matches_a(klm),:),mec,clrmp(matches_a(klm),:),ms,m_size),hold on
                                %text(0, valz(1),num2str(max((timez-first_stim)/10)))
                            end
                        end
                        set(gca,'yticklabel',[]), grid on, ylim([lim 0]), xlim([0 azaz_record(1,2)]), if k~=length(hy),set(gca,'xticklabel',[]),end
                    end
                end
                matches_b=trials_that_were_during_this_epoch(find(azaz_record(trials_that_were_during_this_epoch,1)==hy(k)));
                if ~isempty(matches_b)
                    floor_of_plot=(length(hy)-k)/length(hy);
                    subplot('position',[0.7 floor_of_plot .3 inv(length(hy))])
                    for klm=1:length(matches_b)
                        good_one=multipeak_matrix(:,matches_b(klm));
                        good_one=good_one(~isnan(good_one));
                        first_stim=good_one(1);
                        if length(good_one)>2
                            good_one=good_one(2:end);
                            early_bound=first_stim+azaz_record(matches_b(klm),1)*samples_per_ms+(azaz_record(1,2)*samples_per_ms);
                            timez=good_one(3:5:end);valz=good_one(5:5:end);
                            keepers=timez>early_bound;
                            if find(keepers)
                                timez=timez(find(keepers));valz=valz(find(keepers));
                                plot(((timez-first_stim)/samples_per_ms)-hy(k)-azaz_record(1,2),valz,shapes{epoch},mfc,clrmp(matches_b(klm),:),mec,clrmp(matches_b(klm),:),ms,m_size),hold on
                            end
                        end
                        set(gca,'yticklabel',[]), grid on, ylim([lim 0]), xlim([0 300]),if k~=length(hy),set(gca,'xticklabel',[]),end%still can't see these labels b/c reach the edge of figure
                    end
                end
                
                if length(epoch_dividers)>epoch,trials_that_were_during_this_epoch=[epoch_dividers(epoch)+.5 :epoch_dividers(epoch+1)-.5]
				elseif length(epoch_dividers)==epoch,trials_that_were_during_this_epoch=[epoch_dividers(epoch)+.5:number_of_trials];% mem=number_of_trials,disp('babbyshka')
                end 
            end
        end
    end
end

%colorcode bar
subplot(25,3,70)
colormap jet
imagesc([1:number_of_trials])
set(gca,'ytick',[])
%set(gca,'xTickLabel',get(gca,'xticklabel'),'fontsize',12,'fontname','book antiqua','fontweight','demi')
title('{\itTrial #} ','fontsize',15,'fontname','book antiqua','fontweight','bold'),hold on
for m=1:length(epoch_dividers),plot([epoch_dividers(m) epoch_dividers(m)],[0 2],'w','linewidth',2),end
%text(1,floor(.1*size(plain_rawmatrix,2)),'{\itTrial} \rightarrow','fontsize',15, 'fontname', 'Book Antiqua','fontweight','bold','color','w')
% end