EdgeAlpha for bar plot

10 views (last 30 days)
William De Doncker
William De Doncker on 24 Jan 2020
Commented: Nikhil Sonavane on 30 Jan 2020
Hi there,
I am trying to plot a horizontal line for the value (y) shown below across 3 different x values. Given that I had 2 groups, I tried to do this using the bar plot function and make the FaceColor transparent and then make the vertical and bottom edge transparent. Unfortunately, I cannot seem to figure out how to control individual Edges in bar plot. Seems to be possible in patch plots but not in bar plot. Any idea as to how I can go around this?
This is what I have done so far:
y = [5.14, 5.84;
4.80, 4.42;
5.16; 4.42]
b = bar(y);
b(1).FaceColor = [1 1 1];
b(2).FaceColor = [1 1 1];
b(1).EdgeColor = [0.4 0.4 0.4];
b(2).EdgeColor = [0.7 0.7 0.7];
b(1).LineWidth = 4;
b(2).LineWidth = 4;
b(1).FaceAlpha = 0;
b(2).FaceAlpha = 0;
How can I adjust the transparency of each individual edge of the bar plot?
Any help would be very much appreciated.
William De Doncker

Answers (1)

Nikhil Sonavane
Nikhil Sonavane on 29 Jan 2020
Edited: Nikhil Sonavane on 29 Jan 2020
The output of the mean function which you are using to calculate mean of matrix y is a vector, not a matrix. The function bar returns one or more Bar objects. If y is a vector, then bar creates one Bar object. If y is a matrix, then bar returns a Bar object for each series. In your case only one Bar object is created and hence you are not able to modify individual properties of each bar created in the bar graph. You can refer its documentation for more details. The following is one of the workaround solutions which you can leverage-
y = [5.14, 5.84;4.80, 4.42;5.16, 4.42];
mean_y=mean(y);
hb1 = bar(1,mean_y(1));
hold on
hb2 = bar(2,mean_y(2));
hb1.FaceColor=[1 0 1];
hb2.FaceColor=[0 1 0];
hb1.EdgeColor = [0.4 0.8 0.4];
hb2.EdgeColor = [0.4 0.4 0.4];
hb1.LineWidth = 4;
hb2.LineWidth = 6;
This will help you modify properties of the individual bars as two different bar objects are created.
  2 Comments
Nikhil Sonavane
Nikhil Sonavane on 30 Jan 2020
Edge Propeties of a bar can be accessed by a single identifier. There are no separate identifiers for vertical and horizontal line of a bar. Transparency of all edges of a bar can be modified using EdgeAlpha and not individual edges separately.

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!