Borrar filtros
Borrar filtros

Problem in Plotting bar graph with two y axis (Bars overlapping)

9 visualizaciones (últimos 30 días)
Ahmad Bilal
Ahmad Bilal el 26 de Sept. de 2018
Comentada: Adam Danz el 19 de Mayo de 2020
Hi, I have the following code:
clc;
close all;
clear all;
sheet ='Src_1MIC_Array1';
dataset = xlsread('AllSource_MicArr1.xlsx',sheet,'A4:T51');
ratio_tau_diff = dataset(:,15);
abs_tau_diff = dataset(:,18);
yyaxis left
bar(ratio_tau_diff,'r')
ylabel('Values of ratio tau diff');
yyaxis right
bar(abs_tau_diff,'b')
xlabel('Mic Array 1 pair combinations')
ylabel('Values of abs tau diff');
title('Relative and Absolute differences for Time delays (Tau) (1st Mic Array)');
end
The problem is i am getting overlapping bar graphs. how can I make suitable changes in a code so that they do not come overlap but separately. Thanks
  4 comentarios
Ahmad Bilal
Ahmad Bilal el 26 de Sept. de 2018
I have tried this one but it is showing again not the required result.
yyaxis left
bar(ratio_tau_diff,'r')
ylabel('Values of ratio tau diff');
yyaxis right
bar(abs_tau_diff,'b')
ylim([-0.9 2]);
xlabel('Mic Array 1 pair combinations')
ylabel('Values of abs tau diff');
title('Relative and Absolute differences for Time delays (Tau) (1st Mic Array)');
Can you hep me in this regard??
Ahmad Bilal
Ahmad Bilal el 26 de Sept. de 2018
Can you please modify the code for me. thanks

Iniciar sesión para comentar.

Respuestas (1)

jonas
jonas el 27 de Sept. de 2018
The key here is to plot the two sets of bars as grouped. However, since they are on different axes you cannot plot the two data sets at the same time and thus cannot utilize the standard grouping option. Instead, you create fake groups by padding each vector with NaN's.
% Some data to play with
y1=rand(1,5).*10; %row vector with first set of data
y2=rand(1,5); %row vector with second set of data
% Create two axes
ax1=axes;
ax2=axes('xcolor','none','yaxislocation','right','color','none');
linkaxes([ax1 ax2],'x')
% Pad data with nans
y1=[y1;nan(1,numel(y1))];
y2=[nan(1,numel(y2));y2];
% plot data
axes(ax1);hold on
bar(y1')
axes(ax2);hold on
bar(y2','facecolor',[1 0 0])
xlim([0 length(y2)+1])
  2 comentarios
Adam Danz
Adam Danz el 19 de Mayo de 2020
What does that mean? box on certainly still works (r2020a). 'box' isn't mentioned anywhere on this thread.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by