在条形图matlab中使Y轴以指数方式缩放

时间:2015-01-29 02:32:51

标签: matlab

我正在尝试使用条形图绘制一些数据并且它工作正常,但问题是图中无法识别差异,如下所示,所以我需要将y轴刻度更改为指数因此差异数据之间可以出现..任何帮助? bar chart

这是我的代码:

    x = [0.1 1 10 100 1000 10000];
    y = [2.66    24.58    81.72    87.90    87.99    88.00];
    xplot = 1:numel(x); 
    figure;
    bar(xplot,y);
    set(gca,'XTick', xplot); 
    set(gca,'XTickLabel', x);
    ylim([0 100]);

1 个答案:

答案 0 :(得分:1)

如果您希望y - 轴看起来更均匀,请考虑将比例更改为半对数图,或通过y转换转换log数据:

选项#1 - 将y - 轴更改为log比例:

只需获取当前轴并将YScale设置为log

x = [0.1 1 10 100 1000 10000];
y = [2.66    24.58    81.72    87.90    87.99    88.00];
xplot = 1:numel(x); 
figure;
bar(xplot,y);
set(gca,'XTick', xplot); 
set(gca,'XTickLabel', x);
set(gca,'YScale','log'); %// NEW
%ylim([0 100]); %// Remove as we don't need it

这是我得到的图表:

enter image description here

请注意y - 轴不会改变其数据 - 仅限于您呈现它的方式。蜱以半对数的方式放置,从底部开始,我们从1,2,3到10(10^1),接下来我们走20,30,40到100({{ 1}}),然后我们去200,300,400,最多1000(10^2)等等。你可以在蜱中看到一种模式,因为我们在半对数的基础上增加。

选项#2 - 将您的10^3 - 数据转换为y

只需获取log数据并通过y

运行即可
log

这就是我们得到的:

enter image description here

请注意x = [0.1 1 10 100 1000 10000]; y = [2.66 24.58 81.72 87.90 87.99 88.00]; xplot = 1:numel(x); figure; bar(xplot,log(y)); %// NEW set(gca,'XTick', xplot); set(gca,'XTickLabel', x); %ylim([0 100]); %// Remove as we don't need it - 轴已更改其单位。您可以留下免责声明,说明您的数据已y已转换。