Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
bar3: how to improve the visualization

Subject: bar3: how to improve the visualization

From: pietro

Date: 18 Apr, 2013 17:10:14

Message: 1 of 6

hi all,

I plotted a 3d histogram using the bar3 command of a 24x12 matrix. This is what I made:

http://imageshack.us/a/img829/7953/34753637.jpg

Since the x axis has 12 ticks instead the y one has 24 thicks, the xtick labels are not well displayed. Is it possible to plot not squared bars to enlarge the plot along the x direction to improve its visualization?

Thanks

Best regards

Pietro

Subject: bar3: how to improve the visualization

From: pietro

Date: 24 Apr, 2013 13:57:09

Message: 2 of 6

Can't anyone help me?
Thanks

Regards

Pietro

"pietro " <bracardi82@email.it> wrote in message <kkp9dm$5hu$1@newscl01ah.mathworks.com>...
> hi all,
>
> I plotted a 3d histogram using the bar3 command of a 24x12 matrix. This is what I made:
>
> http://imageshack.us/a/img829/7953/34753637.jpg
>
> Since the x axis has 12 ticks instead the y one has 24 thicks, the xtick labels are not well displayed. Is it possible to plot not squared bars to enlarge the plot along the x direction to improve its visualization?
>
> Thanks
>
> Best regards
>
> Pietro

Subject: bar3: how to improve the visualization

From: matt dash

Date: 26 Apr, 2013 19:58:11

Message: 3 of 6

"pietro " <bracardi82@email.it> wrote in message <kl8obl$2o9$1@newscl01ah.mathworks.com>...
> Can't anyone help me?
> Thanks
>
> Regards
>
> Pietro
>
> "pietro " <bracardi82@email.it> wrote in message <kkp9dm$5hu$1@newscl01ah.mathworks.com>...
> > hi all,
> >
> > I plotted a 3d histogram using the bar3 command of a 24x12 matrix. This is what I made:
> >
> > http://imageshack.us/a/img829/7953/34753637.jpg
> >
> > Since the x axis has 12 ticks instead the y one has 24 thicks, the xtick labels are not well displayed. Is it possible to plot not squared bars to enlarge the plot along the x direction to improve its visualization?
> >
> > Thanks
> >
> > Best regards
> >
> > Pietro

You should post the code that creates the image you show above.

Subject: bar3: how to improve the visualization

From: pietro

Date: 27 Apr, 2013 09:15:10

Message: 4 of 6

"matt dash" wrote in message <klem8i$eu7$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message <kl8obl$2o9$1@newscl01ah.mathworks.com>...
> > Can't anyone help me?
> > Thanks
> >
> > Regards
> >
> > Pietro
> >
> > "pietro " <bracardi82@email.it> wrote in message <kkp9dm$5hu$1@newscl01ah.mathworks.com>...
> > > hi all,
> > >
> > > I plotted a 3d histogram using the bar3 command of a 24x12 matrix. This is what I made:
> > >
> > > http://imageshack.us/a/img829/7953/34753637.jpg
> > >
> > > Since the x axis has 12 ticks instead the y one has 24 thicks, the xtick labels are not well displayed. Is it possible to plot not squared bars to enlarge the plot along the x direction to improve its visualization?
> > >
> > > Thanks
> > >
> > > Best regards
> > >
> > > Pietro
>
> You should post the code that creates the image you show above.

Hi,

this is the code:

function [hist_item ]=istogramma_item_nuovo(segnali,flag,bin_r,bin_c,label_r,label_c,nomeTitolo,mode)
    [dim_r dim_c]=size(segnali);
% Creazione delle label per gli assi
    if dim_r==1
% caso in cui ho dato in input un segnale e voglio un istogramma 2d
        if strcmp(flag,'signal')
            hist_time=histc(segnali,bin_r);
            for i=3:length(bin_r)
                bin_r_cell{i-1}=[num2str(bin_r(i-1)) '÷' num2str(bin_r(i))];
            end
            bin_r_cell{1}=['<' num2str(bin_r(2))];
            bin_r_cell{length(bin_r)-1}=['>' num2str(bin_r(end-1))];
        elseif strcmp(flag,'hist')
            hist_item=segnali;
            bin_r_cell=cellstr(bin_r);
        else
            disp('Il flag è sbagliato: deve valere hist o signal')
        end
        if strcmp(mode,'rel')==1
            hist_item=(hist_item./sum(sum(hist_item)))*100;
        elseif strcmp(mode,'abs')==1
            hist_item=hist_item;
        else
            disp(['Error mode assume valori non consentiti scegliere:' char(10)...
            'rel: per avere il plot in valori percentuali' char(10)...
            'abs: per avere il plot in valori assoluti']);
            return
        end
        figure('units','normalized','outerposition',[0 0 1 1])
        bar(hist_item)
        set(gca,'XTick',[1:length(bin_r_cell)])
        set(gca,'xTickLabel',bin_r_cell)
        xlabel(label_r,'FontSize',16)
        ylabel(label_c,'FontSize',16)
        

    elseif dim_r>2
        if dim_c==2
            segnale_r=segnali(:,1);
            segnale_c=segnali(:,2);
            [hist_item ]=hist3([segnale_r,segnale_c],'Edges',{bin_r',bin_c'});
             % Creazione delle label per gli assi
            for i=3:length(bin_r)
                bin_r_cell{i-1}=[num2str(bin_r(i-1)) '÷' num2str(bin_r(i))];
            end
            bin_r_cell{1}=['<' num2str(bin_r(2))];
            bin_r_cell{length(bin_r)-1}=['>' num2str(bin_r(end-1))];
            for i=3:length(bin_c)
                bin_c_cell{i-1}=[num2str(bin_c(i-1)) '÷' num2str(bin_c(i))];
            end
            bin_c_cell{1}=['<' num2str(bin_c(2))];
            bin_c_cell{length(bin_c)-1}=['>' num2str(bin_c(end-1))];
            
            % và eliminata l'ultime riga e colonna perchè mi mette il numero di
    % valori che assumono un valore pari all'ultimo assunto nei rispettivi
    % array dei bin
            hist_item=hist_item(1:end-1,1:end-1);
        else
            bin_c_cell=bin_c;
            bin_r_cell=bin_r;
            hist_item=segnali;
        end
        if strcmp(mode,'rel')==1
            hist_item=(hist_item./sum(sum(hist_item)))*100;
        elseif strcmp(mode,'abs')==1
            hist_item=hist_item;
        else
            disp(['Error mode assume valori non consentiti scegliere:' char(10)...
            'rel: per avere il plot in valori percentuali' char(10)...
            'abs: per avere il plot in valori assoluti']);
            return
        end
    
        figure('units','normalized','outerposition',[0 0 1 1])
        z=hist_item;
% Questo è da usare nel caso usassi la pcolor
        z(z==0)=NaN;
        h=bar3((hist_item),1);
% h=pcolor(z);
% set(h,'EdgeColor','none')
        [r,c]=find(hist_item==0);
% Rendo bianche le colonne nulle
         for n=1:length(c)
            z=get(h(c(n)),'zdata');
            z((r(n)-1)*6+1:(r(n))*6,:)=NaN;
            set(h(c(n)),'zdata',z);
         end
% Do alle colonne un colore proporzionale alla loro altezza
         for i = 1:length(h)
            zdata = get(h(i),'Zdata');
            set(h(i),'Cdata',zdata)
            set(h(i),'EdgeColor','w')
         end
%
    % è necessaria questa riga per esser sicuri di avere un tick per ogni
    % label
        set(gca,'XTick',[1:length(bin_c_cell)])
        set(gca,'YTick',[1:length(bin_r_cell)])
        set(gca,'yTickLabel',bin_r_cell);%legato alcomando bin1_cell=cellstr(num2str(bin1')) evito di dover inserire a mano gli intervalli
        set(gca,'xTickLabel',bin_c_cell);
        set(gcf,'renderer','opengl');
        view(2)
        grid off
        h_bar=colorbar;
        % Modifica del valore minimo della colorbar da 0 a >0

        cbar_AxisTickLabel=get(h_bar,'YTickLabel');
        cbar_AxisTickLabel=cellstr(cbar_AxisTickLabel);
        cbar_AxisTickLabel{1}=['>' cbar_AxisTickLabel{1}];
        set(h_bar,'YTickLabel',cbar_AxisTickLabel)
        
        box on
        set(gcf,'Color','w')
        if strcmp(mode,'rel')
            h_text=text(1.01 ,1.0221 ,'Time [%]','Units','normalized','FontSize',12)
        end
    end
    if isempty(label_c)==0
        xlabel(label_c,'FontSize',16)
    end
    if isempty(label_r)==0
        ylabel(label_r,'FontSize',16)
    end
    if isempty(nomeTitolo)==0
     title(nomeTitolo,'FontSize',18);
end
    set(gca,'FontSize',14)
end


it's a bit long because it can take one or two time histories to create the histogram, or just an array to plot it as histogram.

Thanks

Cheers

Pietro

Subject: bar3: how to improve the visualization

From: matt dash

Date: 28 Apr, 2013 18:13:09

Message: 5 of 6

"pietro " <bracardi82@email.it> wrote in message <klg4uu$fed$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <klem8i$eu7$1@newscl01ah.mathworks.com>...
> > "pietro " <bracardi82@email.it> wrote in message <kl8obl$2o9$1@newscl01ah.mathworks.com>...
> > > Can't anyone help me?


I think you want to use
set(gca,'plotboxaspectratiomode','auto')
at the end of your code, which will give you non-square bars. If that doesnt work, you can manually set the axes's plotboxaspectratio to control exactly how rectangular the bars are.

Subject: bar3: how to improve the visualization

From: pietro

Date: 29 Apr, 2013 19:38:09

Message: 6 of 6

"matt dash" wrote in message <kljorl$6ue$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message <klg4uu$fed$1@newscl01ah.mathworks.com>...
> > "matt dash" wrote in message <klem8i$eu7$1@newscl01ah.mathworks.com>...
> > > "pietro " <bracardi82@email.it> wrote in message <kl8obl$2o9$1@newscl01ah.mathworks.com>...
> > > > Can't anyone help me?
>
>
> I think you want to use
> set(gca,'plotboxaspectratiomode','auto')
> at the end of your code, which will give you non-square bars. If that doesnt work, you can manually set the axes's plotboxaspectratio to control exactly how rectangular the bars are.

Thank you.

Cheers

Pietro

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us