Bar graph grouped with two y axis

193 visualizaciones (últimos 30 días)
Shu-An Hsieh
Shu-An Hsieh el 6 de Dic. de 2021
Comentada: Adam Danz el 10 de Dic. de 2021
% clc
% clear all
x = categorical({'Filament'; 'Model'});
%y = [0.415047 0.11398; 0.41697 0.013588];
y = [0.415047; 0.41697];
z = [0.11398,0.013588];
bar (x,y,'grouped')
hold on
yyaxis right
%ylim([0.35, 0.45]);
ylabel('Weight (g)');
%err = [0.002542, 0.002192];
%errorbar(A, y, err, '- .', 'MarkerSize', 8)
yyaxis left
%ylim([0, 0.15]);
ylabel('Mass reduction (%)');
%err = [0.003711,0.001355];
%errorbar(A, z, err, '- .', 'MarkerSize', 8)
bar (x,z,'grouped')
hold on
Trying to get a bar graph that share same axis and have two y axis. Tried 'grouped' function but still come out as a stacked bar graph.
  1 comentario
Adam Danz
Adam Danz el 6 de Dic. de 2021
I've formatted your code and produced the resultant figure using the Run feature. What would you like to change about this figure?

Iniciar sesión para comentar.

Respuesta aceptada

Dave B
Dave B el 6 de Dic. de 2021
Editada: Dave B el 6 de Dic. de 2021
bar graphs don't collaborate between sides of a yyaxis very well, but you can fake it by padding with zeros:
x = categorical({'Filament'; 'Model'});
y = [0.415047; 0.41697];
z = [0.11398; 0.013588];
nil = [0; 0];
bar(x, [y nil], 'grouped')
ylabel('Mass reduction (%)');
yyaxis right
bar(x, [nil z], 'grouped')
ylabel('Weight (g)');
  9 comentarios
Shu-An Hsieh
Shu-An Hsieh el 10 de Dic. de 2021
Thank you so much for the help this is really helpful!
Adam Danz
Adam Danz el 10 de Dic. de 2021
Thanks for the reminder, Dave. I couldn't remember if I had used those newer properties or not but it looks like I did.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by