insert two vertical axes (left and right) into the same bar graph

5 次查看(过去 30 天)
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?

采纳的回答

Voss
Voss 2023-9-19
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)

更多回答(1 个)

Image Analyst
Image Analyst 2023-9-19
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.

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by