在Matlab中使用对数刻度x轴且宽度相同的绘图栏 [英] Plot bar in matlab with log-scale x axis and same width
本文介绍了在Matlab中使用对数刻度x轴且宽度相同的绘图栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Matlab中绘制条形图,其中(1)x轴的对数刻度和(2)相同宽度的条形图.但是在下面的代码中,条形的宽度是不同的.有人可以帮忙吗?非常感谢!
I want to plot a bar chart in Matlab with (1) log-scale for x-axis and (2)bars in same width. But with the code below, the width of the bars are different. Can any one help? Many thanks!
xdata = [0.01 0.018 0.032 0.056 0.1 0.18 0.32 0.56 1 1.8 3.2 5.6 10];
ydata = [1.3 1.6 1.5 1.2 1.0 3.5 0.6 3.1 1.6 1.9 1.7 0.3 0.4];
bar(xdata,ydata);
set(gca,'XScale','log');
推荐答案
与其以对数刻度绘制xdata
,而不是以线性刻度绘制xdata
的对数.然后修改标签以反映线性值(而不是使用的对数值).
Instead of plotting xdata
on a log scale, plot the log of xdata
on a linear scale. Then modify labels to reflect the linear value (not the used log value).
xdata = [0.01 0.018 0.032 0.056 0.1 0.18 0.32 0.56 1 1.8 3.2 5.6 10];
ydata = [1.3 1.6 1.5 1.2 1.0 3.5 0.6 3.1 1.6 1.9 1.7 0.3 0.4];
bar(log10(xdata),ydata);
set(gca,'Xtick',-3:1); %// adjust manually; values in log scale
set(gca,'Xticklabel',10.^get(gca,'Xtick')); %// use labels with linear values
这篇关于在Matlab中使用对数刻度x轴且宽度相同的绘图栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文