Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Alberto Acri
Alberto Acri am 19 Sep. 2023
Beantwortet: Voss am 19 Sep. 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?

Akzeptierte Antwort

Voss
Voss am 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)

Weitere Antworten (1)

Image Analyst
Image Analyst am 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.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by