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

12 次查看(过去 30 天)
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 个评论
Ahmad Bilal
Ahmad Bilal 2018-9-26
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??

请先登录,再进行评论。

回答(1 个)

jonas
jonas 2018-9-27
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])

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by