Graphics, Figures & TablesHow to draw multiple Rectangles from input data file

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
taniamalik
Posts: 1
Joined: Tue Nov 13, 2012 2:08 am

How to draw multiple Rectangles from input data file

Post by taniamalik »

Hi
I want to draw set of rectangles on axis based on input file. My .tex file should be some thing like that

Code: Select all

\documentclass{article}
\usepackage{tikz,pgf}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{fit,calc}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=8cm,
height=8cm,
scale only axis,
xmin=-1, xmax=20,
ymin=-1, ymax=20,
xlabel={i},
ylabel={j},
title={Hi}]
\pgfplotstableread{data.dat}\table;
for each row in table
if (\gg=0)
{
 \draw [black, fill=blue, thick] (axis cs:\x,\y) rectangle (axis cs:\xx,\yy);
    \end{axis}
else if (\gg=1)
\draw [black, fill=red, thick] (axis cs:\x,\y) rectangle (axis cs:\xx,\yy);
    \end{axis}
else if (\gg=2)
\draw [black, fill=red, thick] (axis cs:\x,\y) rectangle (axis cs:\xx,\yy);
    \end{axis}
	\end{tikzpicture}
	\end{document}
Where as my input file look like

Code: Select all

%% data.dat 
x	y	xx	yy	gg	
0	0	5	4	0	  
0	4	5	9	1
0	9	5	13	0
0	13	5 	16	1
5	0	9	5       2
Plz help me out how can I draw them.
Thanks
Last edited by cgnieder on Tue Nov 13, 2012 1:03 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

How to draw multiple Rectangles from input data file

Post by svend_tveskaeg »

Hi taniamalik.

Welcome to the board! (I hope a welcome greeting i not for moderators only...)

I do not know TikZ, but what I do know, is that you can (1) edit your post, (2) mark all the code belonging to your TeX file, and (3) click the botton "Code" above the editing window. Then the code will be nicely formatted.

Update
Cross-posting is no-go unless you link properly (if you ask me)!

http://tex.stackexchange.com/questions/ ... data-file/
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply