Change color of x axis and y axis barplot

3 Ansichten (letzte 30 Tage)
forgood2
forgood2 am 17 Jun. 2021
Bearbeitet: Scott MacKenzie am 17 Jun. 2021
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?

Akzeptierte Antwort

Scott MacKenzie
Scott MacKenzie am 17 Jun. 2021
Bearbeitet: Scott MacKenzie am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by