# How to draw rectangles with cartesian axes and dimensional constraints in Tikz

I want to draw exactly the same figure attached using Tikz-PGF package in lateX. How can I do that. I appreciate any help, because I have to submit a paper, and it was kind of last minute addition. Thanks

This service "do-it-for-me" ...

\begin{tikzpicture}
\draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
\draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[very thick]   (0,0) |- (5,1) -- (5,0)
(2,0) |- (3,2) -- (3,0);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
\end{tikzpicture}


That above code will work, you need to preamble add \usetikzlibrary{arrows.meta}. Result:

Addendum: As request in comment below ... follows three cases of possible coloring of "rectangles":

Complete small document, called Minimal Working Example (MWE), which produce above images, is

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
% colored lines
\begin{tikzpicture}
\draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
\draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[red,very thick]  % <--- changed
(0,0) |- (5,1) -- (5,0);
(2,0) |- (3,2) -- (3,0);

\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
\end{tikzpicture}

\begin{tikzpicture}
% colored lines and fill
\draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
\draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[draw=red,fill=red!30,very thick]   % <--- changed
(0,0) |- (5,1) -- (5,0);
(2,0) |- (3,2) -- (3,0);

\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
\end{tikzpicture}

\begin{tikzpicture}
% colored lines and fill, added transparency
\draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
\draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[draw=red,fill=red!30,very thick,semitransparent]  % <--- changed
(0,0) |- (5,1) -- (5,0);
\draw[draw=blue,fill=blue!30,very thick,semitransparent]% <--- changed
(2,0) |- (3,2) -- (3,0);

\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
(0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
\end{tikzpicture}
\end{document}

• Thanks. I understand why you said that. I've never done this before. But searching for doing this took me all morning, and I couldn't find the answer. Thanks again, I appreciate it. – David Mar 10 '16 at 20:55
• Is it possible to color each rectangular alone? – David Mar 10 '16 at 21:27
• Yes, it is possible. just line: draw=color or fill fill=color. I add examples of three coloring. – Zarko Mar 11 '16 at 3:50
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9944213032722473, "perplexity": 8673.374542885354}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-30/segments/1563195529737.79/warc/CC-MAIN-20190723215340-20190724001340-00506.warc.gz"}