Change color of x axis and y axis barplot

3 views (last 30 days)
I want a barplot with two different y axis in different colors. The x axis should be in black.
Here is my code:
a=[rand(3,1)*100 zeros(3,1) ];
b=[zeros(3,1) rand(3,1)*5 ];
[AX,H1,H2] =plotyy([1:3],a, [1:3],b, 'bar', 'bar');
set(H1,'FaceColor','r') % a
set(H2,'FaceColor','b') % b
set(AX,{'ycolor'},{'r';'b'})
The problem is the x axis whisch should be in black.
I tried
set(AX,{'ycolor'},{'r';'b'}, {'xcolor'}, {'k'})
but the x axis colour did not change.
Does anybody know how to fix this problem?

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 17 Jun 2021
Edited: Scott MacKenzie on 17 Jun 2021
I think this achieves what you are after. Note that plotyy is "not recommended".
a = [rand(3,1)*100, zeros(3,1)];
b = [zeros(3,1), rand(3,1)*5];
yyaxis left;
bar(1:3,a);
yyaxis right;
bar(1:3,b);

More Answers (0)

Categories

Find more on Color and Styling 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!