简体   繁体   中英

Changing the axis of a histogram plot in Matlab

I want to simulate values that represent a geometric distribution. The plot I have done using the code below seems to produce the right plot. But I want the x axis is badly out of position and also I want the x-axis to be numbered 1,2,3,etc instead of the 10,20,30,etc that I receive now. I also want to plot the Y-axis as a log scale.I am trying to get the plot of 'X' given in the code.

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

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

在此处输入图片说明

Plotting a bar graph with log scale is tricky. See: How to plot hist with log scale , or use this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM