我试图用柱状图绘制一些数据,它工作正常,但问题是,如下所示的差异不是从图中可识别的,所以我需要改变Y轴的规模是指数如此的数据之间的差异可出现..任何帮助?
这是我的代码:
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]);
如果你想y
轴看起来更均匀,考虑改变规模,以半对数坐标图,或通过y
改造将您log
数据:
y
-axis to log
scale:简单地获取当前坐标轴,并设置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
这是我得到的图形:
要留意的是,y
轴不改变它的数据 - 只有你呈现的方式。蜱被放置在一个半对数基础,其中来自底部,我们从1去,2,3,最多10(10^1
),接下来,我们去20,30,40,最多100(10^2
),那么我们去200,300,400,最多1000(10^3
)等等。你当然可以看到在蜱的模式,因为我们是一个半对数的基础上增加。
y
-data to log
:只要把你的y
数据,并通过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,log(y)); %// NEW
set(gca,'XTick', xplot);
set(gca,'XTickLabel', x);
%ylim([0 100]); %// Remove as we don't need it
这就是我们得到:
要留意的是,y
轴已经改变了单位。您可以留下一个声明说,您的数据log
转化。