【发布时间】:2018-10-06 05:24:14
【问题描述】:
我正在尝试从电子表格中读取值并通过 MATLAB 绘制它们。但是,当第一个数据集的值变低时,它会隐藏在后面,如下面的值80 和100 所示:
我在想可能是因为我在同一点上绘制了两个不同的bar 图。如何将较短的条放在前面?
下面是我的代码:
%{
Data example:
Arrival_rate per_A per_B
30 46.361 44.892
60 30.585 25.602
80 20.674 23.352
100 16.209 18.597
%}
fig = figure('DefaultAxesFontSize',18);
set(0,'DefaultAxesFontName','Times New Roman');
arrival_rate = xlsread('Graph_data', 'Sheet2', 'H1:H6');
pe_a = xlsread('Graph_data', 'Sheet2', 'I1:I6');
pe_b = xlsread('Graph_data', 'Sheet2', 'J1:J6');
line = xlsread('Graph_data', 'Sheet2', 'K1:K6');
x1 = 30:1:100;
y1 = [46.361 44.892; 30.585 25.602; 16.209 18.597];
x2 = 30:1:100;
y2 = interp1(arrival_rate,line,x2,'pchip') ;
hold on
ylabel('% error in VM_A')
% bar(arrival_rate,y, 0.2, 'b', 'DisplayName', 'Error in A')
bar(arrival_rate,pe_a ,.1 , 'stacked','DisplayName', 'Error in A')
bar(arrival_rate,pe_b, .1 , 'stacked', 'DisplayName', 'Error in B')
% bar(arrival_rate, y1, 0.2, 'hist')
plot(x2,y2,'k.','HandleVisibility','off','LineWidth',1)
plot(arrival_rate,line,'k*', 'HandleVisibility','off','LineWidth',1)
hold off
xlabel('\lambda (Clients/Hour) ')
ylabel('Error (%)')
% title('Effect of Probability of a VM Type on awt of Clients')
legend show
legend('Location','Northeast')
set(gca,'XTick',(0:10:110))
set(gca,'YTick',(0:5:50))
set(gcf, 'PaperUnits', 'normalized')
set(gcf, 'PaperOrientation', 'landscape')
set(gcf, 'PaperPosition', [0 0 1 1])
【问题讨论】:
-
您能分享您的 Excel 表格(或至少是数字),以便测试代码吗?
-
@Anton!请查看已编辑的问题。
标签: matlab plot bar-chart visualization matlab-figure