Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am interested on drawing (I suspect that using pgf/tikz is one of the easiest ways to accomplish this) a picture like the following one enter image description here

It is supposed to be a grid of the plane (I only care about the points with natural coordinates), where there are some "red bags" which contain some of these points , and there is a region that is coloured on yellow (one of the red bags corresponds exactly to the points in the yellow region).

Any idea about how to use pgf/tikz to draw something like this?

share|improve this question
1  
Why dont you use a drawing program such as Inkscape or LibreOffice Draw rather then spending hours programming something? –  Danie Els Apr 25 '12 at 14:37
1  
Welcome to TeX.SE. It would be helpful to show what you have tried so far, and what exactly you are having issues with. For instance, have you been able to draw the grid? –  Peter Grill Apr 25 '12 at 14:38
    
Indeed to start looking at the manual on my own I would like to know which is the right command to use for the grid, and which is the one to use for the bags. –  boumol Apr 25 '12 at 14:54
    
@boumol: You can draw the grid using \draw (0,0) grid (3.5,3.5);, for example. For drawing the "bags", you can use \draw [rounded corners=0.2cm] (<coordinate>) -- (<coordinate>) -- <and so on>;. –  Jake Apr 25 '12 at 15:20
    
@Jake: What about the colored region? –  boumol Apr 25 '12 at 16:08
show 1 more comment

1 Answer

up vote 2 down vote accepted

I am just expanding @Jake's comments into an answer.

\documentclass[border=.1cm]{standalone} %change to article or whatever...
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \fill [green!80!blue] (3.5,0) -- (3,0) -- (3,1) -- (2,1) -- (2,2) -- (1,2) -- (1,3.5) -- (3.5,3.5) -- cycle;
\draw[thin] (0,0) grid (4.5,4.5);
\draw[brown,ultra thick] (0,0) circle (0.3cm);
\draw [rounded corners=0.2cm,brown,very thick] (1.2,-0.4) -- (1.2,1.3) -- (0.8,1.3) -- (0.8,-0.4) -- cycle;
\draw[brown,ultra thick] (2,0) circle (0.3cm);
\draw [rounded corners=0.2cm,brown,very thick]  (0.2,4.3) --  (0.2,0.8) --  (-0.2,0.8) -- (-0.2,4.3);
\foreach \x in {0,1,2,3,4}
\foreach \y in {,0,1,2,3,4}
{
\draw[fill=black] (\x,\y) circle (1pt);
}
% \fill [green!80!blue,opacity=.4] (3.5,0) -- (3,0) -- (3,1) -- (2,1) -- (2,2) -- (1,2) -- (1,3.5) -- (3.5,3.5) -- cycle;
\draw [rounded corners=0.2cm,brown,very thick]  (4.3,-0.3) --  (2.8,-0.3) --  (2.8,0.8) -- (1.8,0.8) -- (1.8,1.8) -- (0.8,1.8) -- (0.8,4.3);
\end{tikzpicture}
\end{document}

enter image description here

Instead of putting

\fill [green!80!blue] (3.5,0) -- (3,0) -- (3,1) -- (2,1) -- (2,2) -- (1,2) -- (1,3.5) -- (3.5,3.5) -- cycle;

in the beginning you can put it anywhere and use opacity = .4 ( or any value as you like) as:

\fill [green!80!blue,opacity=.4] (3.5,0) -- (3,0) -- (3,1) -- (2,1) -- (2,2) -- (1,2) -- (1,3.5) -- (3.5,3.5) -- cycle;

to get

enter image description here

Pl. note that I have used a very conventional and simple way of putting coordinates. Things can be made more complex and neat.

share|improve this answer
    
Thanks. This has helped me a lot. –  boumol Apr 27 '12 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.