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}
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
Thanks