Change color of x axis and y axis barplot

18 visualizaciones (últimos 30 días)
forgood2
forgood2 el 17 de Jun. de 2021
Editada: Scott MacKenzie el 17 de Jun. de 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?

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 17 de Jun. de 2021
Editada: Scott MacKenzie el 17 de Jun. de 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);

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by