probem with FaceColor of bar

4 views (last 30 days)
mohamed gryaa
mohamed gryaa on 30 Sep 2019
Commented: darova on 4 Oct 2019
R=[0.779810425627480 0.000659297275251825 0.688360393160301 0.184532497610895 0.0905962113611394 0.0626722269195076 0.115760244765211 9.82482188727207e-06]
R2=[0.780896183843548 0.783089437325240 0.824384828931732 0.783480655246833 0.782324163937975 0.843400789787716 0.780259820660027 0.692761472581375 0.186630591612089 0.112331622540645 0.0684118151132265 0.124754260377728 0.000750940658416743 0.786209417062528 0.696211586340910 0.704468853008563 0.793533655775326 0.689231222654964 0.247394539787509 0.259526400351099 0.187357565089202 0.306685869655797 0.221985207424738 0.213936150337528 0.0911810803863357 0.226392210021089 0.0628097955366125 0.177330398333869]
R3=[0.783714743066040 0.826211863604426 0.783570491492865 0.784235776628874 0.846564931503649 0.781795435841793 0.824795480225099 0.793293977502063 0.807394055917125 0.843543223850931 0.784225204506264 0.828604905652616 0.830131797565598 0.845605618105580 0.866367812401167 0.784125887674771 0.844962871032082 0.783775317173255 0.857006696649914 0.782646132825257 0.886525345744327 0.792443729599900 0.707602204791307 0.706291944439437 0.795689075333992 0.692960273475268 0.269367754096017 0.269897642276868 0.187804460375981 0.338233654026156 0.308011853235251 0.214628124374582 0.117141128901629 0.229057283333948 0.0684491039966618 0.183900696434232 0.789982210441524 0.793671406033401 0.807345796487103 0.835447142202684 0.705376496011716 0.804011717368906 0.696706432568307 0.795703083661133 0.705025556256066 0.832447316043765 0.383708291936295 0.256938376298548 0.368132130189507 0.275653288847231 0.375594581589765 0.328508421589727 0.426445219789627 0.222082122851731 0.295080637436694 0.303500075279901]
R4=[0.826996774935897 0.794557334602349 0.809619574536623 0.846642577477218 0.785322675618129 0.828939025798648 0.833675796861419 0.847202474959195 0.881468153988862 0.784703824104669 0.851106275596922 0.784004921796498 0.858781120350036 0.785070083916637 0.888559577339896 0.828833804725073 0.834955475482176 0.846195401779085 0.867140402842741 0.813983848871127 0.845075441261779 0.794705445368061 0.872508246817512 0.810962400206204 0.886525524768893 0.831303117637229 0.847642143194423 0.868934285031242 0.858409734520770 0.872566944267203 0.906757870765131 0.857428757371442 0.784387451549559 0.886620441089954 0.905697241656523 0.801922541124688 0.797636506176264 0.807358981738157 0.862781849694327 0.710334094086818 0.804080272956492 0.707686352900283 0.798434388040983 0.706487674364295 0.833750942309195 0.471755923663536 0.270095621013156 0.456472753439997 0.277630257351045 0.430498750484947 0.343336309036551 0.454955851249911 0.317945379843094 0.298347039374467 0.304574520635417 0.794166474258310 0.814390776564570 0.840239456373557 0.810347726332535 0.841150193698107 0.877516625338572 0.804070982436114 0.705841896439888 0.849259411824625 0.832907343342206 0.437358816488236 0.495244980869643 0.405878538783720 0.424820970524598 0.547495448988831]
R5=[0.828991929369686 0.838411193709899 0.847498079098537 0.884286848091013 0.813984689455561 0.852689268734507 0.795461615160834 0.873675836205425 0.815033194461026 0.888567443766334 0.833676221089556 0.851532466108260 0.881503316538568 0.859249568891160 0.893364109834186 0.907586430555856 0.858785564028645 0.785320228500511 0.889516792068951 0.906442600699576 0.838035644265987 0.847642955904863 0.868937970747267 0.873278896824283 0.876253552968026 0.908008036718245 0.872689586925684 0.817720580546422 0.886663386046064 0.937203366812540 0.858609315682532 0.872839144872220 0.907099734481859 0.924204051669980 0.910846971035114 0.802163827732857 0.815595411648910 0.884996077524746 0.810350740286317 0.864252213958193 0.883287964927457 0.804103360669447 0.710335861966019 0.849504374181575 0.834436602026480 0.484612221304780 0.704965265425382 0.460974241930084 0.447415007134505 0.598056626502316 0.814518098488400 0.842523239334591 0.888286770499680 0.878177732084617 0.852719060026541 0.604403396129531]
R6=[0.839071360465035 0.852704784532168 0.887822544505265 0.876021378692969 0.896575199509569 0.909363801082844 0.875080432727216 0.818093523631484 0.890239643298577 0.937369178243077 0.859250167086107 0.903297054324622 0.907629634392680 0.926273966668406 0.911091067394923 0.873423351158586 0.877473297910146 0.908008113026594 0.941060841208969 0.938200096744872 0.927636099224910 0.815597023464531 0.891134879647912 0.903795572804284 0.883537686178393 0.854841118650416 0.733815636601844 0.889727749438983]
R7=[0.878642031246962 0.903669866631326 0.910417834781449 0.941547570214469 0.938233123072641 0.937500290384948 0.942085824188201 0.914574284340743]
R8=[0.945329036585856]
R_all = [R R2 R3 R4 R5 R6 R7 R8];
label_all = [label,label2,label3,label4,label5,label6,label7,label8];
[R_all_sort,ind_sort] = sort(R_all,'descend');
label_all_sort = label_all(ind_sort);
threshold = 0.95;
logical_index = R_all_sort>=threshold;
N_true = length(find(logical_index));
figure
hall=bar(R_all_sort(logical_index));
hold on
grid on
xlabel('metriche lavatrice');
ylabel('R^2 lavatrice ');
ax=gca;
ax.XTick = 1:N_true;
ax.XTickLabels = label_all_sort(logical_index);
ax.XTickLabelRotation = 90;
legend({'soggettività:lavatrice' });
ylim([threshold 1]);
hi i have a problem, i need to have differet color when i plot the figure bar (Facecolor) like this:
R = red
R2= green
R3= white
R4 =cyan
R5=blue
R6=yellow
R7=black
R8= magenta
  1 Comment
dpb
dpb on 30 Sep 2019
threshold = 0.95;
logical_index = R_all_sort>=threshold;
...
>> sum(logical_index)
ans =
0
>> max(R_all)
ans =
0.9453
>>
There are no elements above the threshold so nothing will show up on the plot.
Also, you've mixed all elements up in combining into one long vector and then sorted that vector so there's no identification from which element any particular value came.
Would need to define corollary array of group number to carry along.

Sign in to comment.

Accepted Answer

darova
darova on 30 Sep 2019
One way:
R=[0.779810425627480 0.000659297275251825 0.688360393160301 0.184532497610895 0.0905962113611394 0.0626722269195076 0.115760244765211 9.82482188727207e-06];
R2=[0.780896183843548 0.783089437325240 0.824384828931732 0.783480655246833 0.782324163937975 0.843400789787716 0.780259820660027 0.692761472581375 0.186630591612089 0.112331622540645 0.0684118151132265 0.124754260377728 0.000750940658416743 0.786209417062528 0.696211586340910 0.704468853008563 0.793533655775326 0.689231222654964 0.247394539787509 0.259526400351099 0.187357565089202 0.306685869655797 0.221985207424738 0.213936150337528 0.0911810803863357 0.226392210021089 0.0628097955366125 0.177330398333869];
R3=[0.783714743066040 0.826211863604426 0.783570491492865 0.784235776628874 0.846564931503649 0.781795435841793 0.824795480225099 0.793293977502063 0.807394055917125 0.843543223850931 0.784225204506264 0.828604905652616 0.830131797565598 0.845605618105580 0.866367812401167 0.784125887674771 0.844962871032082 0.783775317173255 0.857006696649914 0.782646132825257 0.886525345744327 0.792443729599900 0.707602204791307 0.706291944439437 0.795689075333992 0.692960273475268 0.269367754096017 0.269897642276868 0.187804460375981 0.338233654026156 0.308011853235251 0.214628124374582 0.117141128901629 0.229057283333948 0.0684491039966618 0.183900696434232 0.789982210441524 0.793671406033401 0.807345796487103 0.835447142202684 0.705376496011716 0.804011717368906 0.696706432568307 0.795703083661133 0.705025556256066 0.832447316043765 0.383708291936295 0.256938376298548 0.368132130189507 0.275653288847231 0.375594581589765 0.328508421589727 0.426445219789627 0.222082122851731 0.295080637436694 0.303500075279901];
R4=[0.826996774935897 0.794557334602349 0.809619574536623 0.846642577477218 0.785322675618129 0.828939025798648 0.833675796861419 0.847202474959195 0.881468153988862 0.784703824104669 0.851106275596922 0.784004921796498 0.858781120350036 0.785070083916637 0.888559577339896 0.828833804725073 0.834955475482176 0.846195401779085 0.867140402842741 0.813983848871127 0.845075441261779 0.794705445368061 0.872508246817512 0.810962400206204 0.886525524768893 0.831303117637229 0.847642143194423 0.868934285031242 0.858409734520770 0.872566944267203 0.906757870765131 0.857428757371442 0.784387451549559 0.886620441089954 0.905697241656523 0.801922541124688 0.797636506176264 0.807358981738157 0.862781849694327 0.710334094086818 0.804080272956492 0.707686352900283 0.798434388040983 0.706487674364295 0.833750942309195 0.471755923663536 0.270095621013156 0.456472753439997 0.277630257351045 0.430498750484947 0.343336309036551 0.454955851249911 0.317945379843094 0.298347039374467 0.304574520635417 0.794166474258310 0.814390776564570 0.840239456373557 0.810347726332535 0.841150193698107 0.877516625338572 0.804070982436114 0.705841896439888 0.849259411824625 0.832907343342206 0.437358816488236 0.495244980869643 0.405878538783720 0.424820970524598 0.547495448988831];
R5=[0.828991929369686 0.838411193709899 0.847498079098537 0.884286848091013 0.813984689455561 0.852689268734507 0.795461615160834 0.873675836205425 0.815033194461026 0.888567443766334 0.833676221089556 0.851532466108260 0.881503316538568 0.859249568891160 0.893364109834186 0.907586430555856 0.858785564028645 0.785320228500511 0.889516792068951 0.906442600699576 0.838035644265987 0.847642955904863 0.868937970747267 0.873278896824283 0.876253552968026 0.908008036718245 0.872689586925684 0.817720580546422 0.886663386046064 0.937203366812540 0.858609315682532 0.872839144872220 0.907099734481859 0.924204051669980 0.910846971035114 0.802163827732857 0.815595411648910 0.884996077524746 0.810350740286317 0.864252213958193 0.883287964927457 0.804103360669447 0.710335861966019 0.849504374181575 0.834436602026480 0.484612221304780 0.704965265425382 0.460974241930084 0.447415007134505 0.598056626502316 0.814518098488400 0.842523239334591 0.888286770499680 0.878177732084617 0.852719060026541 0.604403396129531];
R6=[0.839071360465035 0.852704784532168 0.887822544505265 0.876021378692969 0.896575199509569 0.909363801082844 0.875080432727216 0.818093523631484 0.890239643298577 0.937369178243077 0.859250167086107 0.903297054324622 0.907629634392680 0.926273966668406 0.911091067394923 0.873423351158586 0.877473297910146 0.908008113026594 0.941060841208969 0.938200096744872 0.927636099224910 0.815597023464531 0.891134879647912 0.903795572804284 0.883537686178393 0.854841118650416 0.733815636601844 0.889727749438983];
R7=[0.878642031246962 0.903669866631326 0.910417834781449 0.941547570214469 0.938233123072641 0.937500290384948 0.942085824188201 0.914574284340743];
R8=[0.945329036585856];
R_all = [R R2 R3 R4 R5 R6 R7 R8];
color_ind = [R*0+1 R2*0+2 R3*0+3 R4*0+4 R5*0+5 R6*0+6 R7*0+7 R8*0+8];
cm = 'rgwcbykm'; % reg green white ...
[R_all_sort,ind_sort] = sort(R_all,'descend');
color_sort = color_ind(ind_sort);
threshold = 0.95;
ind1 = find( R_all_sort<=threshold );
cla
hold on
for i = ind1
h = bar(ind1(i),R_all_sort(i));
set(h,'EdgeColor','none','FaceColor',cm(color_sort(i)))
end
hold off
But works slow. Any idea of how speed it up?
  6 Comments

Sign in to comment.

More Answers (1)

dpb
dpb on 30 Sep 2019
Edited: dpb on 30 Sep 2019
Carrying on from the above after defining data...
clrs=[[1 0 0];[0 1 0];[1 1 1];[0 1 1];[0 0 1];[1 1 0];[0 0 0];[1 0 1]]; % rgb for named colors
R1=R; % just for symmetry in naming
G=[1+R1*0 2+R2*0 3+R3*0 4+R4*0 5+R5*0 6+R6*0 7+R7*0 8+R8*0];
threshold=0.925; % 0.95 > max() --> no elements selected
ix=(R_all>=threshold);
R=R_all(ix);
[~,isort]=sort(R,'descend');
hBar=bar(R(isort));
hBar.FaceColor='flat';
hBar.CData=clrs(isort(G),:);
returns

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!