필터 지우기
필터 지우기

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

조회 수: 9 (최근 30일)
Ahmad Bilal
Ahmad Bilal 2018년 9월 26일
댓글: Adam Danz 2020년 5월 19일
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??
Ahmad Bilal
Ahmad Bilal 2018년 9월 26일
Can you please modify the code for me. thanks

댓글을 달려면 로그인하십시오.

답변 (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])
  댓글 수: 2
Adam Danz
Adam Danz 2020년 5월 19일
What does that mean? box on certainly still works (r2020a). 'box' isn't mentioned anywhere on this thread.

댓글을 달려면 로그인하십시오.

카테고리

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