Editing 2D Drawing using Tikz in Latex

tikz-pgftikz-styles

I'm trying to edit a 2D figure using Tikz. My current code and plot are as follow:

    \usepackage{tikz}
    \usepackage{graphicx}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{xcolor}`

    \begin{document}

    \begin{figure}[hbt]
    \centering
    \begin{tikzpicture}[scale=350]
    \centering
    \draw[blue,thick] (0,0) -- (0.0219837,0)-- (0.0219837,0.0168148)-- (0.0056579,0.0168148) -- (0.0052959,0.0127) -- (0.0027051,0.0127) -- (0.0027051,0.0142494)--(0,0.0142494) -- cycle;
    %\filldraw[fill=green!20,draw=green!50!black] 

   \draw[line width=1mm, red] (0.0024, 0.0142495) -- (0.0024, 0.01225);
   \draw[line width=1mm, green] (0.0024, 0.0122495) -- (0.0024, 0.002);
   \draw[line width=1mm, black] (0.0024, 0.002, 0.0) -- (0.0024, 0.0);
   \draw[line width=0.55mm, magenta] (0.0, 4.0E-8) -- (0.0219837, 4.0E-8);

   \end{tikzpicture}
   \caption{2D domain.}
   \label{fig:2D Domain}
   \end{figure}

   \end {document}

This provides me the following figure:

enter image description here

Now, I'd like to edit my figure as follow: i.e. each of the newly added lines (3 Vertical, 1 horizontal) should have the legends with respective colors as indicated in the figure. For example, I have used, red, green, blue, and magenta. Also, I want them to be aligned.

enter image description here

Best Answer

Just draw the lines at the desired positions and add a node at their end. For example:

\draw[line width=1mm, red] (0.005,0.01) -- (0.0075,0.01) node [right] {Line 1};

I don't know if you need to preserve the line widths, if this is not the case remove them.

This could be the complete code:

\documentclass[tikz,border=5mm]{standalone}

\begin{document}
\begin{tikzpicture}[scale=350]
\centering
\draw[black,thick] (0,0) -- (0.0219837,0) -- (0.0219837,0.0168148) -- (0.0056579,0.0168148) --
                   (0.0052959,0.0127) -- (0.0027051,0.0127) -- (0.0027051,0.0142494) -- (0,0.0142494) -- cycle;

\draw[line width=1mm, red]        (0.0024, 0.0142495) -- (0.0024, 0.01225);
\draw[line width=1mm, green]      (0.0024, 0.0122495) -- (0.0024, 0.002);
\draw[line width=1mm, blue]       (0.0024, 0.002)     -- (0.0024, 0.0);
\draw[line width=0.55mm, magenta] (0.0, 4.0E-8)       -- (0.0219837, 4.0E-8);
% Legend
\draw[line width=1mm, red]        (0.005,0.01)   -- (0.0075,0.01)   node [right] {Line 1};
\draw[line width=1mm, green]      (0.005,0.0085) -- (0.0075,0.0085) node [right] {Line 2};
\draw[line width=1mm, blue]       (0.005,0.007)  -- (0.0075,0.007)  node [right] {Line 3};
\draw[line width=0.55mm, magenta] (0.005,0.0055) -- (0.0075,0.0055) node [right] {Line 4};
\end{tikzpicture}
\end{document}

enter image description here