%
% GENERATE DATA FROM THE BINOMIAL DISTRIBUTION
%
% Define the k-values at which the distribution is to be evaluated
k = 0:40;
% Evaluate the binomial distribution at these values
prob = pdf(makedist('Binomial','N',20000,'p',0.001),k);

%
% GENERATE A PLOT FROM THE DATA AND CONTROL ITS APPEARANCE
%
% The figure command generates a figures window
fig=figure(2);
% The set command sets the properties of the figure 'fig'
set(fig,...
    'Color','w',...
    'Name','Binomial Distribution',...
    'PaperSize',[7 5.08],...
    'PaperPosition',[0 0 7 5.08],...
    'InvertHardcopy','off');

% The stem command generates a stem-plot of the data
h = stem(k,prob,'fill');

% The set command sets the properties of the current axes
set(gca,...
    'FontName','Times New Roman',...
    'FontSize',24,...
    'XTick',0:10:40,...
    'Ytick',0:0.02:0.1,...
    'Color',[0.8 0.8 0.8],...
    'LineWidth',2,...
    'TickLength',[0.02 0.0250],...
    'XLim',[0 40],...
    'YLim',[0 0.1],...
    'Units','inches',...
    'Position',[1.05 0.8 5.77 3.57],...
    'Layer','Top')

% The xlabel and ylabel commands specify the axes labels and their
% properties; they can be interpreted in latex
xlabel('$$k$$','Interpreter','latex')
ylabel('$$\mathrm{prob}\,(k|n,p)$$','Interpreter','latex')

% The text command places text in the figure at a specific position
text(25,0.08,'$$p=0.001$$','Interpreter','latex','FontSize',24);
text(25,0.065,'$$n=20''000$$','Interpreter','latex','FontSize',24);

% The title command defines the title above the axes
title('The binomial distribution')

% The saveas command saves the plot to a file, here a pdf file
saveas(gcf,'binomial_Matlab','pdf');