EdgeAlpha for bar plot

25 次查看(过去 30 天)
William De Doncker
William De Doncker 2020-1-24
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

回答(1 个)

Nikhil Sonavane
Nikhil Sonavane 2020-1-29
编辑:Nikhil Sonavane 2020-1-29
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 个评论
William De Doncker
William De Doncker 2020-1-29
Hi Nikhil,
Thank you for your answer. The variable name 'mean_y' was a mistake and have now modified this in the original question. I basically wanted to plot matrix 'y'. Also, your solution does not seem to answer the question. I can modify the FaceColor and EdgeColor, but what I wanted to know is whether you can modify the transparency of each edge using EdgeAlpha? I want to make the two vertical edges and the bottom horizontal edge of each bar transparent so that only the top hoirzontal edge is visible.
Here is what I wanted to achieve:
example.JPG
I managed to do get what I wanted using a far from ideal method, by overlaying a white bar over the orginal with a new y-axis value of y-(a number).
Cheers,
Will
Nikhil Sonavane
Nikhil Sonavane 2020-1-30
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by