insert two vertical axes (left and right) into the same bar graph
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 19 Sep 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 Comments
More Answers (1)
Image Analyst
on 19 Sep 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 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!