Bar series plot, transparent colors on the bars

I use Matlab v. R2014b and have a problem with setting the bar series plot to have transparent colors. I add 9 different data sets (given by a&b) on one single plot/figure, using a for-loop and the hold on comand. A simplification of the code is given here:
-------------------------------------------------------------
plotStyle = {'b','k','r','g','c','m','y',[1 0.270588 0],[0.180392 0.545098 0.341176]}; %setting colors for the plot
for i=1:9 %starting for-loop
a=[1; 2; 3; 4; 5]; %vector giving moment, x-axis
b=[10; 3; 5; 7; 9]; %vector giving number of occurences, y-axis
z=rand();
a=a.*z;
b=b.*z;
% Both a & b is updated for every round of the loop, here exemplified with use of a random number
figure (1)
bar(a,b,'FaceColor',plotStyle{i},'EdgeColor',plotStyle{i});
legendInfo{i} = ['Overpull' num2str(i)];
hold on
end %ending for-loop
legend(legendInfo) %displaying legend
-----------------------------------------
To get transparent bar I therefore tried to add "FaceAlpha" in the "bar-command", but this is not allowed for barseries as far as I have found out. I have also tried using handles with pathces, but this doesent seem to work with this version of matlab... Does anyone have a solution on how to get transparent colors on the bars?

 채택된 답변

Brendan Hamm
Brendan Hamm 2015년 5월 6일

0 개 추천

Try the solution I have pasted in another post ... just last night. I have made a function which creates the patches necessary to create a transparent bar plot.

댓글 수: 2

kathrigr
kathrigr 2015년 5월 6일
Perfect! however, i had a problem with my labels when using this patch function you created(the labels come up in the plot, but the colors are not correct(all blue)). Do you know if there is a simple way of including labels in this function?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thomas Koelen
Thomas Koelen 2015년 5월 6일

0 개 추천

They explain how to it on this website:
Only works on 2014B, well earlier versions can do it aswell but it is a lot of hassle.

댓글 수: 4

kathrigr
kathrigr 2015년 5월 6일
Hi, thank you for the tip. But as it is a barplot, the marker handle command does not work and the following error message occurs:
No appropriate method, property, or field MarkerHandle for class matlab.graphics.chart.primitive.Bar.
Error in: hMarkers = hLine.MarkerHandle;
If i try to use only hLine.get there is not possibile to add a fourth number in the color vector:
While setting the 'FaceColor' property of Bar: Color value must be a 3 element vector
Error in: hLine.FaceColor = uint8(255*[1;0;0;0.3]);
Is there another handle that should be used instead as it is a barplot or is this solution just not suited for barplots?
Try this:
B = bar(rand(1,40));
ch = get(B,'child');
set(ch,'facea',.05)
The children of bar is now empty post 2014b so this will not work.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

2015년 5월 6일

댓글:

2018년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by