I want colours to be assigned to all the different bars (ranging from B_{1} to B_{15}) in my number line.
% !TeX program = lualatex
\documentclass[a4paper,14pt]{extarticle}
\usepackage{mathptmx}% http://ctan.org/pkg/mathptmx% is TIME NEW ROMANS
\usepackage{tgtermes} % times font
%\usepackage{wordlike}% Emulate MS Word
\usepackage{setspace}
% Double spacing
%\doublespacing
%% One and half spacing
\onehalfspacing
% the below reduce space between section header and text
\usepackage{titlesec}
\titlespacing{\section}{0pt}{\parskip}{\parskip}
\titlespacing{\subsection}{0pt}{\parskip}{\parskip}
\titlespacing{\subsubsection}{0pt}{\parskip}{\parskip}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{amssymb,amsfonts,amsmath,graphicx,autobreak}
\usepackage{changepage,mathtools,amsthm,tikz,blindtext}
\usepackage{inputenc,float,caption,subcaption,enumitem}
\usepackage[font=large,labelfont=bf,font=normalfont,labelsep=colon]{caption}
\usepackage[font=small,labelfont=bf,font=bf,labelsep=colon]{subcaption}
\usepackage{csquotes} %for single quoatation mark
\usepackage{tikz}
\begin{document}
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
% draw horizontal line
\draw (0,0) -- (17,0);
% draw vertical lines
\foreach \x in {0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5,14.5,15.5,16.5,17.5}
\draw (\x cm,5pt) -- (\x cm,-0pt);
% draw nodes
\draw (0.5,0) node[above=5pt] {$ x_{1} $} node[above=5pt] {$\rm $};
\draw (1.5,0) node[above=5pt] {$ x_{2} $} node[above=5pt] {$\rm $};
\draw (2.5,0) node[above=5pt] {$ x_{3} $} node[above=5pt] {$\rm $};
\draw (3.5,0) node[above=5pt] {$ x_{4} $} node[above=5pt] {$\rm $};
\draw (4.5,0) node[above=3pt] {$ x_{5} $} node[above=5pt] {$\rm $};
\draw (5.5,0) node[above=5pt] {$ x_{6} $} node[above=5pt] {$\rm $};
\draw (6.5,0) node[above=3pt] {$ x_{7} $} node[above=5pt] {$\rm $};
\draw (7.5,0) node[above=5pt] {$ x_{8} $} node[above=5pt] {$\rm $};
\draw (8.5,0) node[above=3pt] {$ x_{9} $} node[above=5pt] {$\rm $};
\draw (9.5,0) node[above=3pt] {$ x_{10} $} node[above=5pt] {$\rm $};
\draw (10.5,0) node[above=3pt] {$ x_{l1} $} node[above=5pt] {$\rm $};
\draw (11.5,0) node[above=3pt] {$ x_{l2} $} node[above=5pt] {$\rm $};
\draw (12.5,0) node[above=3pt] {$ x_{l3} $} node[above=5pt] {$\rm $};
\draw (13.5,0) node[above=3pt] {$ x_{14} $} node[above=5pt] {$\rm $};
\draw (14.5,0) node[above=3pt] {$ x_{l5} $} node[above=5pt] {$\rm $};
\draw (15.5,0) node[above=3pt] {$ x_{16} $};
\draw (16.5,0) node[above=5pt] {$ x_{n} $} node[above=5pt] {$\rm $};
\draw [-] (0.5,-0.1) -- (0.5,-0.5);
\draw [-] (2.5,-0.1) -- (2.5,-0.5);
\draw [-] (0.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{1} $} (2.5,-0.3); %1
\draw [-] (1.5,0.9) -- (1.5,0.5);
\draw [-] (3.5,0.9) -- (3.5,0.5);
\draw [-] (1.5,0.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{2} $} (3.5,0.7); %2
\draw [-] (2.5,-0.6) -- (2.5,-1.0);
\draw [-] (4.5,-0.6) -- (4.5,-1.0);
\draw [-] (2.5,-0.8) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{3} $} (4.5,-0.8); %3
\draw [-] (3.5,1.0) -- (3.5,1.4);
\draw [-] (5.5,1.0) -- (5.5,1.4);
\draw [-] (3.5,1.2) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{4} $} (5.5,1.2); %4
\draw [-] (4.5,-0.1) -- (4.5,-0.5);
\draw [-] (6.5,-0.1) -- (6.5,-0.5);
\draw [-] (4.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{5} $} (6.5,-0.3); %5
\draw [-] (5.5,0.9) -- (5.5,0.5);
\draw [-] (7.5,0.9) -- (7.5,0.5);
\draw [-] (5.5,0.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{6} $} (7.5,0.7); %6
\draw [-] (6.5,-0.6) -- (6.5,-1.0);
\draw [-] (8.5,-0.6) -- (8.5,-1.0);
\draw [-] (6.5,-0.8) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{7} $} (8.5,-0.8); %7
\draw [-] (7.5,1.0) -- (7.5,1.4);
\draw [-] (9.5,1.0) -- (9.5,1.4);
\draw [-] (7.5,1.2) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{8} $} (9.5,1.2); %8
\draw [-] (8.5,-0.1) -- (8.5,-0.5);
\draw [-] (10.5,-0.1) -- (10.5,-0.5);
\draw [-] (8.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{9} $} (10.5,-0.3); %9
\draw [-] (9.5,0.9) -- (9.5,0.5);
\draw [-] (11.5,0.9) -- (11.5,0.5);
\draw [-] (9.5,0.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{10} $} (11.5,0.7); %10
\draw [-] (10.5,-0.6) -- (10.5,-1.0);
\draw [-] (12.5,-0.6) -- (12.5,-1.0);
\draw [-] (10.5,-0.8) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{11} $} (12.5,-0.8); %11
\draw [-] (11.5,1.0) -- (11.5,1.4);
\draw [-] (13.5,1.0) -- (13.5,1.4);
\draw [-] (11.5,1.2) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{12} $} (13.5,1.2); %12
\draw [-] (12.5,-0.1) -- (12.5,-0.5);
\draw [-] (14.5,-0.1) -- (14.5,-0.5);
\draw [-] (12.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{13} $} (14.5,-0.3); %13
\draw [-] (13.5,0.9) -- (13.5,0.5);
\draw [-] (15.5,0.9) -- (15.5,0.5);
\draw [-] (13.5,0.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{14} $} (15.5,0.7); %14
\draw [-] (14.5,-0.6) -- (14.5,-1.0);
\draw [-] (16.5,-0.6) -- (16.5,-1.0);
\draw [-] (14.5,-0.8) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{15} $} (16.5,-0.8); %15
\end{tikzpicture}
\caption{ Moving Block Bootstrap: Block size $= 2$, Overlapping $= 1$}
\label{fig1}
\end{center}
\end{figure}
\end{document}
I want the colour of the bar B_{1} to be different from bar B_{1} and so forth.
I also want the font colour for the number line itself ($x_{1}, x_{2}, \dots, x_{n}$) to be uniform while the font colour for the bars ($B_{1}, B_{2}, \dots, B_{15}$) to be uniformly different also.

mathptmxpackage is considered obsolete, I think\usepackage{newtxmath}is recommended instead (see https://ctan.org/pkg/mathptmx). 2) All thenode[above=5pt] {$\rm $}are unnecessary, and note that\rmhas been considered deprecated since the 90s. If it's math, probably use\mathrm{...}instead of\rm .... 3) Finally, insidefigureenvironments\centeringis recommended over acenterenvironment: https://tex.stackexchange.com/a/2652 – Torbjørn T. Jun 28 '21 at 15:52