insert two vertical axes (left and right) into the same bar graph
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alberto Acri
el 19 de Sept. de 2023
Respondida: Voss
el 19 de Sept. de 2023
Hi! How can I enter the correct values into the y-axis on the right? They must match the values of CountArray(:,3)!
load CountArray_1.mat
CountArray = CountArray_1;
x = CountArray(:,1).';
y = CountArray(:,2);
% x = CountArray(:,3).';
% y = CountArray(:,2);
figure
E = barh(x,y,'FaceColor',[1 0 0],'EdgeColor',[0 0 0]);
yyaxis left
ylabel('Values A', 'FontSize', 13);
yyaxis right
ylabel('Values B', 'FontSize', 13);
xlabel('Rep', 'FontSize', 13)
Also, is it possible to impose the color black and not orange as shown in the figure?
0 comentarios
Respuesta aceptada
Voss
el 19 de Sept. de 2023
load CountArray_1.mat
CountArray = CountArray_1;
x = CountArray(:,1).';
y = CountArray(:,2);
% x = CountArray(:,3).';
% y = CountArray(:,2);
figure
E = barh(x,y,'FaceColor',[1 0 0],'EdgeColor',[0 0 0]);
yyaxis left
yticks(x) % optional, depending on what you want to see
ylim([x(1)-1 x(end)+1])
ylabel('Values A', 'FontSize', 13);
yyaxis right
set(gca(),'YColor','k')
yticks(CountArray(:,3)) % optional, depending on what you want to see
ylim([CountArray(1,3)-1 CountArray(end,3)+1])
ylabel('Values B', 'FontSize', 13);
xlabel('Rep', 'FontSize', 13)
0 comentarios
Más respuestas (1)
Image Analyst
el 19 de Sept. de 2023
Wow, that is confusing. As a consumer of your data visualization, that would be very confusing for me to interpret.
What I'd recommend is if you want the third column to be associated with each bar, then use text to place the number from the third column just to the right of the bar. Let me know if you can't figure that out.
To change just about anything in a graph (font size, color, etc.) see attached demo.
0 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!