how do I prevent bar3 shading the sides of the bars?
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    

Hi there,
I have never used MATLAB bar charts before and I am trying to show four-dimensional data, such that the height of the bars refers to the frequency of an x,y combination and the color refers to another dataset.
I am using this code which I found as an answer to a different question.
A = rand(10,10);
A2 = rand(10,10);
figure(1)
b1= bar3(A);
figure(2)
b = bar3(A2);
hcb = colorbar;
for k = 1:length(b)
    b(k).CData = b1(k).ZData;
    b(k).FaceColor = 'flat';
end
The code was originally written using FaceColor 'interp' but I would like one color per bar. As you can see, when I use 'flat', I get the colors I want, but shading on the sides of the bars which I really don't want.
Any ideas on how to get rid of this would be appreciated!
1 Commento
  dpb
      
      
 il 29 Mag 2018
				The HG2 bar and surface objects are incredibly dense and difficult to penetrate the maze, I agree.
What you need is to be able to set .FaceColor = rgb triplet of the color from the previous scaled by the .ZData but for the life of me on a quick perusal I've no idea how, specifically, to retrieve the values desired/needed.
Risposta accettata
  dpb
      
      
 il 30 Mag 2018
        
      Modificato: dpb
      
      
 il 30 Mag 2018
  
      OK, I did figure out how to modify the .ZData values written to get the proper effect.
...
for k = 1:length(b)
  zd=b1(k).ZData;                       % retrieve the ZData to write as CData
  ix=isfinite(zd(:,1));                 % the faces with color values locations
  zd(ix,1)=zd(ix,2);                    % use same color for first coordinate, too
  b(k).CData = zd;
  b(k).FaceColor = 'flat';
end
Used subplot() to shrink images down but above mod yields

The key to how/why this works is shown in the documentation for surface properties under 'FaceColor' in how the 'CData' value is interpreted.  NB: for 'flat' the LLH corner location is used for the associated face and the default value for that location in the 4-vector in bar3 is 0 for the base color of the scaled range, but the second/third vertices are set to the scaled values. The above simply replaces that zero with the scaled value for the second and thus the face to the left is now also the same color.
Somewhere in there is undoubtedly a flag/property that could be tweaked to generate the CData values to not shade the one face but I couldn't find it; it came to me overnight I had done something like this quite some time ago but I had to reinvent it as had forgotten just what/how.
2 Commenti
  dpb
      
      
 il 30 Mag 2018
				No problem; I've fiddled with bar -related queries quite a lot over the years. I've railed at TMW for how difficult the interface is for anything but "out of the box" and how many what seem obvious needs aren't available without excessive gyrations.
The depth of detailed knowledge required to make such changes surely defeats the purpose of "rapid development"; I don't have a canned solution to hand them, but it just seems like there should be some way to reduce the complexity markedly.
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Annotations in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!