Plot bar in matlab with log-scale x axis and same width

帅比萌擦擦* 提交于 2019-12-14 03:45:50

问题


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');


回答1:


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



来源:https://stackoverflow.com/questions/22410715/plot-bar-in-matlab-with-log-scale-x-axis-and-same-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!