matlab 如何将零值图例显示为图例中的一条线?

piwo6bdm  于 2022-11-30  发布在  Matlab
关注(0)|答案(1)|浏览(236)

下面的例子显示了以下向量的条形图:

% % For Phi/Psi = +/-10
CoverageArea_mean_10 = [84.4735,21.1779,6.4247,2.1416]; 
CoverageArea_min_10 = [98.5128,21.1779,6.9007,2.1416]; 
CoverageArea_max_10 = [70.1963,19.0363,5.9488,2.1416];
% For Phi/Psi = +/-40
CoverageArea_mean_40 = [0,4.5211,2.3795,0]; 
CoverageArea_min_40 = [92.5640,21.1779,6.9007,2.1416]; 
CoverageArea_max_40 = [0,0.4759,0.2380,0];

如下所示

  • 问题是有一些零值,我需要在图例上将它们表示为一条线。如何修复它?*

预期结果:

%% Plotting the coverage area
x = [15,30,45,60];
figure
COVERAGE = [CoverageArea_min_10;CoverageArea_mean_10;CoverageArea_max_10];
COVERAGEAREA = [COVERAGE(:,1)';COVERAGE(:,2)';COVERAGE(:,3)';COVERAGE(:,4)'];
bar(x,COVERAGEAREA);
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
figure
COVERAGE1 = [CoverageArea_min_40;CoverageArea_mean_40;CoverageArea_max_40];
COVERAGEAREA1 = [COVERAGE1(:,1)';COVERAGE1(:,2)';COVERAGE1(:,3)';COVERAGE1(:,4)'];
bar(x,COVERAGEAREA1);
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
zz2j4svz

zz2j4svz1#

close all; clear all;
% Create figure
figure1 = figure('WindowState','maximized');

% Create axes
axes1 = axes('Parent',figure1);
hold(axes1,'on');

% Create multiple lines using matrix input to bar
% % For Phi/Psi = +/-10
CoverageArea_mean_10 = [84.4735,21.1779,6.4247,2.1416]; 
CoverageArea_min_10 = [98.5128,21.1779,6.9007,2.1416]; 
CoverageArea_max_10 = [70.1963,19.0363,5.9488,2.1416];
% For Phi/Psi = +/-40
CoverageArea_mean_40 = [0,4.5211,2.3795,0]; 
CoverageArea_min_40 = [92.5640,21.1779,6.9007,2.1416]; 
CoverageArea_max_40 = [0,0.4759,0.2380,0]; 
%% Plotting the coverage area
x = [15,30,45,60];

COVERAGE = [CoverageArea_min_10;CoverageArea_mean_10;CoverageArea_max_10];
COVERAGE1 = [CoverageArea_min_40;CoverageArea_mean_40;CoverageArea_max_40];
COVERAGEAREA1 = [COVERAGE1(:,1)';COVERAGE1(:,2)';COVERAGE1(:,3)';COVERAGE1(:,4)'];
COVERAGEAREA = [COVERAGE(:,1)';COVERAGE(:,2)';COVERAGE(:,3)';COVERAGE(:,4)'];

bar1 = bar(x,COVERAGEAREA1,'Parent',axes1);
set(bar1(3),'DisplayName','min');
set(bar1(2),'DisplayName','mean');
set(bar1(1),'DisplayName','max');

% Create ylabel
ylabel('Coverage area $(m^2)$','Interpreter','latex');

% Create xlabel
xlabel('$\phi_{1/2}$','Interpreter','latex');

box(axes1,'on');
grid(axes1,'on');
hold(axes1,'off');
% Set the remaining axes properties
set(axes1,'XTick',[15 30 45 60]);
% Create legend
legend1 = legend(axes1,'show');
set(legend1,'Interpreter','latex','AutoUpdate','off','Location','best');

% Create rectangle
annotation(figure1,'rectangle',...
    [0.854166666666666 0.861889927310488 0.0223958333333336 0.0290758047767393],...
    'Color',[1 1 1],...
    'FaceColor',[1 1 1]);

% Create line
annotation(figure1,'line',[0.8578125 0.873958333333333],...
    [0.881619937694704 0.881619937694704]);

% Create line
annotation(figure1,'line',[0.858333333333333 0.8734375],...
    [0.867082035306334 0.867082035306334]);

相关问题