在Matlab中为对数图选择其他基准 [英] Select a different base for a logarithmic plot in matlab
本文介绍了在Matlab中为对数图选择其他基准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让x轴对数为2:从2 ^ 10到2 ^ 25,并且每一步的指数都应增加1,而y轴应该是线性的.
I want to have the x-axis logarithmic to the base 2: From 2^10 to 2^25 and at each step the exponent should increase by one, while the y-axis should be linear.
这怎么可能?我已经想通了
How is this possible? I already figured out
set(gca,'XScale','log')
但是你不能设置基础.
推荐答案
请考虑以下示例:
%# some random data
x = 2.^(0:10);
y = rand(size(x));
plot(log2(x), y) %# plot on log2 x-scale
set(gca, 'XTickLabel',[]) %# suppress current x-labels
xt = get(gca, 'XTick');
yl = get(gca, 'YLim');
str = cellstr( num2str(xt(:),'2^{%d}') ); %# format x-ticks as 2^{xx}
hTxt = text(xt, yl(ones(size(xt))), str, ... %# create text at same locations
'Interpreter','tex', ... %# specify tex interpreter
'VerticalAlignment','top', ... %# v-align to be underneath
'HorizontalAlignment','center'); %# h-aligh to be centered
这篇关于在Matlab中为对数图选择其他基准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文