changing bar color to black and white

4 views (last 30 days)
Hello every body
I want to change the color of a bar element to black and white, I don't know how to use the RGB codes of the colors.
bar(mydata, ' stacked ', 'color' , 'DimGray');
As I googled I find '65 65 65' for RGB code of 'dimGray' , and also I used
bar(mydata, ' stacked ', 'color' , [ 65 65 65 ]);
but it doesn't work out.
Could anyone help me in this issue?
Appreciate your kind help.

Accepted Answer

Robert U
Robert U on 29 Sep 2017
Hi Vahid_68,
the function bar does not support your command. Colors have to be given as normalized values in the range [0..1] and there is no property 'color'.
One way (even though you cannot distinguish matched segments) is to call the following commands:
x = rand(5);
bar(x,'stacked','FaceColor',[0.65 0.65 0.65])
That gives you a grey faced bar with 5 segments each.
Kind regards,
Robert
  2 Comments
Walter Roberson
Walter Roberson on 29 Sep 2017
bar(mydata, ' stacked ', 'color' , [ 65 65 65 ]);
should become
bar(mydata, ' stacked ', 'color' , [ 65 65 65 ]/255);
Robert U
Robert U on 29 Sep 2017
Edited: Robert U on 29 Sep 2017
Hi Walter Roberson:
You are right about the scaling factor for 8bit rgb color space only. And, the property 'color' is not available for bar-plots as rgb-triplet.
Kind regards,
Robert

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots 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!