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

4 visualizzazioni (ultimi 30 giorni)
Alberto Acri il 19 Set 2023
Risposto: Voss il 19 Set 2023
Hi! How can I enter the correct values into the y-axis on the right? They must match the values of CountArray(:,3)!
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Voss il 19 Set 2023
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Image Analyst il 19 Set 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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Bar Plots in Help Center e File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by