N = 1e6;
lambda = 1/2;
x = exprnd(1/lambda,1,N);

%

histogram(x,50,'Normalization','pdf')
grid on
z = linspace(min(x),max(x));
hold on
plot(z,lambda*exp(-z*lambda),'LineWidth',1.5);
hold off
xlabel('x')
ylabel('f_X(x)')
legend('Histogram','Theory')

%

grid on
z = linspace(min(x),max(x));
semilogy(z,lambda*exp(-z*lambda),'LineWidth',1.5);
hold on
histogram(x,30,'Normalization','pdf')
hold off
xlabel('x')
ylabel('f_X(x)')