Effacer les filtres
Effacer les filtres

changing color while using 'hist' in a bar-plot

20 vues (au cours des 30 derniers jours)
Jakob Sievers
Jakob Sievers le 7 Nov 2011
Hi there
When using the 'hist' option while plotting a bar figure, I can't seem to figure out how to change the facecolor and the edgecolor of the bars. Specifically I would like both to be red. This is easily changed using bar(data), but using bar(data,'hist'), those options seem unavailable. Using the example from mathworks.com:
y = [75.995 91.972 105.711 123.203 131.669 ...
150.697 179.323 203.212 226.505 249.633 281.422];
bar(y,'facecolor','r','EdgeColor','r'); ---> WORKS
bar(y,'hist','facecolor','r','EdgeColor','r'); ---> DOES NOT WORK.
I guess the problem is that I have to write the correct property-value pair for 'hist' when using other property-value pairs simultaneously, but I can't figure out which property 'hist' is part of.
Thanks in advance!

Réponse acceptée

Sam Roberts
Sam Roberts le 7 Nov 2011
Try:
h = bar(y,'hist');
set(h,'FaceColor','r','EdgeColor','r');
If you take a look at the doc page for bar, you'll see that with the 'hist' option you can't pass in additional parameter/value pairs. In addition, while the main form of bar returns a barseries object, with the 'hist' option it returns patches. You can grab a handle to the patches and set the colors yourself as above.
  2 commentaires
Jakob Sievers
Jakob Sievers le 7 Nov 2011
Thank you for this advice. It worked beautifully.
Cesar Toledo
Cesar Toledo le 8 Mar 2013
How is this done? How can I grab the handle of the patches?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Identification dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by