Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: bar3: how to improve the visualization
Replies: 5   Last Post: Apr 29, 2013 3:38 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
pietro

Posts: 374
Registered: 1/3/09
Re: bar3: how to improve the visualization
Posted: Apr 27, 2013 5:15 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.