Break y Axis&误差棒

时间:2014-03-20 09:08:46

标签: matlab plot

您可以从HERE

下载.xlsx文件

代码

figure('Units', 'pixels', 'Position', [100 100 800 375]);

RSM = xlsread('RSM_V_PSO.xlsx', 'Sheet1', 'C4:F103');
PSO = xlsread('RSM_V_PSO.xlsx', 'Sheet1', 'M4:P103');

ci_RSM = bootci(1000, @mean, RSM);
ci_PSO = bootci(1000, @mean, PSO);

Media_tot_RSM = mean(RSM,1)';
Media_tot_PSO = mean(PSO,1)';

ci_RSM = abs(ci_RSM' - repmat(Media_tot_RSM,1,2)) .* [1.9, 0.8, 0.6, 0.4; 1.9, 0.8, 0.6, 0.4]';
ci_PSO = abs(ci_PSO' - repmat(Media_tot_PSO,1,2));

ydata_m_RSM = (Media_tot_RSM');
ydata_m_PSO = (Media_tot_PSO');
xdata_m = [2 4 6 8];

[xData_RSM, yData_RSM] = prepareCurveData( xdata_m, ydata_m_RSM );
[xData_PSO, yData_PSO] = prepareCurveData( xdata_m, ydata_m_PSO );

hFit_RSM = plot(xData_RSM, yData_RSM,'.');
hold on
hFit_PSO = plot(xData_PSO, yData_PSO,'.');
hE_RSM   = errorbar(xdata_m, ydata_m_RSM, ci_RSM(:,1), ci_RSM(:,2));
hE_PSO   = errorbar(xdata_m, ydata_m_PSO, ci_PSO(:,1), ci_PSO(:,2));


hXLabel = xlabel('Objective function calls');
hYLabel = ylabel('Objective Function');

xlim([1 9]);
ylim([8.07 8.35]);

set(hFit_RSM                          , ...
'Color'           , [0 .2 .6]    );
set(hE_RSM                            , ...
'LineStyle'       , 'none'      , ...
'Marker'          , '.'         , ...
'Color'           , [0 .2 .6], ...
'markersize', 6);
set(hE_PSO                            , ...
'LineStyle'       , 'none'      , ...
'Marker'          , '.'         , ...
'Color'           , [.8 .3 .3], ...
'markersize', 6);

hLegend = legend([hE_RSM hE_PSO],'RSM Data \pm 95% CI', 'PSO Data \pm 95% CI', 'location', 'NorthEast' );
set(gca,'XTick',[2 4 6 8]);

输出:

First

然后,使用BreakPlot打破yaxis给我这个:

代码2:

breakplot(xData_RSM,yData_RSM,8.095,8.335,'Line');

输出2:Second

问题:

  1. 有没有更好的方法来执行此操作?
  2. 错误栏hE_RSM消失了。我怎么能避免这种情况?

1 个答案:

答案 0 :(得分:0)

替代 - 需要一些编程或在绘图编辑器中工作。

我通常为这样的任务放置两个轴,一个用于顶部,一个用于下部。我在两者中绘制相同的数据,但是然后使用轴放大两者的正确范围。 需要做一些调整才能很好地放置它们,并且还要转换不必要的传说。

通常我也会制作一个小的第三轴并绘制两条线,其中斧头已被切割