【问题标题】:Changing the axis of a histogram plot in Matlab在 Matlab 中更改直方图的轴
【发布时间】:2011-12-05 18:43:24
【问题描述】:

我想模拟代表几何分布的值。我使用下面的代码完成的情节似乎产生了正确的情节。但我希望 x 轴严重偏离位置,并且我希望 x 轴编号为 1、2、3 等,而不是我现在收到的 10、20、30 等。我还想将 Y 轴绘制为对数刻度。我正在尝试获取代码中给出的“X”图。

%Geometric Distribution%
N=100;%Number of simulation
P=0.1;
X=zeros(N,1);%simulation data
Ti=0;%Counter

for Ti=2:N
  U=rand(1);
  a=log10(U);
  b=log10(1-P);
  c=(a/b);
  d=1+round(c);
  X(Ti)=d;
  Ti=Ti+1;
end

t = 0:N-1;
hist(X);

【问题讨论】:

    标签: matlab matlab-figure


    【解决方案1】:

    hist(X,min(X):max(X))

    【讨论】:

    • 当我使用 x 轴作为 10、20、30 等时,我得到了我想要的形状。但是当我使用它时,形状是可怕的错误。我不知道如何上传直方图,否则我可以显示我想要的形状
    • 你可以这样做: hist(X,n), n 将是 bin 的数量。所以你可以调整 n 来得到你想要的。
    【解决方案2】:

    用对数比例绘制条形图很棘手。请参阅:How to plot hist with log scale,或使用此:

    [n, xout] = hist(X,0:max(X));
    bar(xout, n, 'barwidth', 1, 'basevalue', 1);
    set(gca,'YScale','log')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多