How can one specify the color of comparison bar chart?

1 vue (au cours des 30 derniers jours)
alpedhuez
alpedhuez le 30 Juil 2021
Modifié(e) : alpedhuez le 30 Juil 2021
Suppose I have
bin_age = ['test', 2];
vals = [ 1 1; 2 2];
b = bar(vals)
newXticklabel = {'young', 'old'}
set(gca,'XtickLabel',newXticklabel);
xlabel('Product');
How can one change the colors of the first bars (blues) and the second bars (oranges)?

Réponse acceptée

dpb
dpb le 30 Juil 2021
Just answered for another a few minutes ago @ <problem-with-grouped-bar-plot>
You also have a grouped bar plot as your data are arranged as a 2x2 array -- so 2 groups of 2 bars/group.
The .CData property is the only way to change individual bars, likewise it's the way to change all bars of the two bar handles because as you've probably already discovered, the 'Color' property in the bar() argument list is applied to every bar globally, and there's no provision to supply a vector of colors to associate with each row (group) on a 1:1 basis.
I've railed at TMW for 30 years about the poor interface to bar() on such things that the implementation is extremely "user-beligerent" as opposed to "user-friendly".
  6 commentaires
alpedhuez
alpedhuez le 30 Juil 2021
Modifié(e) : alpedhuez le 30 Juil 2021
I did talk to a tech support.
dpb
dpb le 30 Juil 2021
Oh, really! That IS surprising, indeed.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by