フィルターのクリア

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 件のコメント
Lars Abrahamsson
Lars Abrahamsson 2020 年 5 月 19 日
box on
doesn't work anylonger though
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 Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by