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.

How can we draw diagrams like this:

enter image description here

and

enter image description here

share|improve this question
8  
Slowly and carefully. –  percusse Aug 7 '13 at 7:28
5  
Welcome to TeX.sx! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. –  ChrisS Aug 7 '13 at 7:31
1  
For what it's worth: you could check out examples for TikZ. Then please do prepare an MWE. :) –  henry Aug 7 '13 at 7:38
    
something that might get you started: How to draw function domain/co-domain (range) diagram? –  cmhughes Aug 7 '13 at 8:23
add comment

1 Answer

up vote 6 down vote accepted

enter image description here

This kind of diagrams can be easily created in Asymptote in several simple steps:

prepare arrays of points, that define curves and contours, for example:

// Left contour points
pair[] pa={
(134,37),
(193,47),
(196,82),
(150,111),
(90,117),
(33,98),
(9,73),
(7,57),
(29,48),
(80,49),
};

build the actual curves (paths) from prepared points and draw them (..cycle is added in case of closed contour):

guide ga=graph(pa,operator..)..cycle;    
draw(ga,linePen);

prepare arrays of TeX labels and their coordinates and draw them in a for-loop:

pair[] labelPos={
(71,76),
(232,103),
(406,71),
(446,110),
};

string[] labelTeX={
"$(X,T)$",
"$f:X\rightarrow Z$",
"$Z$",
"$(Y,T^\prime)$",
};

for(int i=0;i<labelTeX.length;++i){
  label(labelTeX[i],labelPos[i]);
}

The second diagram needs a filldraw command to draw a filled region.

A complete source diag.tex is here:

\documentclass{article}
\usepackage[inline]{asymptote}

\begin{document}
\begin{figure}
\begin{asy}
size(400);
import graph;

// Left contour points
pair[] pa={
(134,37),
(193,47),
(196,82),
(150,111),
(90,117),
(33,98),
(9,73),
(7,57),
(29,48),
(80,49),
};

// Right outer contour points
pair[] pb={
(453,25),
(469,41),
(483,58),
(494,84),
(485,112),
(462,132),
(441,138),
(422,146),
(411,149),
(389,147),
(357,140),
(280,100),
(268,86),
(261,74),
(267,65),
(277,57),
(291,38),
(307,17),
(337,8),
(401,7),
};

// Right inner contour points
pair[] pc={
(414,48),
(426,67),
(425,100),
(401,110),
(376,111),
(343,104),
(330,102),
(314,89),
(306,81),
(309,71),
(316,63),
(332,57),
(356,46),
(386,40),
};


// Arrow points
pair[] parrow={
(122,79),
(234,93),
(372,73),
};

pair[] labelPos={
(71,76),
(232,103),
(406,71),
(446,110),
};

string[] labelTeX={
"$(X,T)$",
"$f:X\rightarrow Z$",
"$Z$",
"$(Y,T^\prime)$",
};

defaultpen(fontsize(10pt));
pen linePen=darkblue+1.2bp;

for(int i=0;i<labelTeX.length;++i){
label(labelTeX[i],labelPos[i]);
}

guide ga=graph(pa,operator..)..cycle;
guide gb=graph(pb,operator..)..cycle;
guide gc=graph(pc,operator..)..cycle;
guide garrow=graph(parrow,operator..);

draw(ga,linePen);
draw(gb,linePen);
draw(gc,linePen);

draw(garrow,linePen,Arrows(HookHead,size=3));
\end{asy}
\\[20pt]
\begin{asy}
size(400);
import graph;

// Outer contour points
pair[] pb={
(283,46),
(296,60),
(301,94),
(295,134),
(284,171),
(258,198),
(233,205),
(206,215),
(189,220),
(164,217),
(116,201),
(76,176),
(35,144),
(14,120),
(6,107),
(4,85),
(6,68),
(14,47),
(38,49),
(70,47),
(102,41),
(134,35),
(170,29),
(203,24),
(237,26),
(263,35),
};

// Inner contour points
pair[] pc={
(163,107),
(181,111),
(199,121),
(209,134),
(212,151),
(201,172),
(181,179),
(159,180),
(126,172),
(97,162),
(78,145),
(65,133),
(65,124),
(74,119),
(82,120),
(99,120),
(119,117),
(142,115),
};

// span points

pair[] pspan={
(476,120),
(604,120),
};


// Arrow points
pair[] parrow1={
(197,77),
(324,149),
pspan[0]
};

pair[] parrow2={
(189,153),
(218,169),
(266,192),
(327,202),
(395,202),
(433,198),
(466,192),
(508,182),
(541,168),
(568,151),
pspan[0]*(1-0.95)+pspan[1]*0.95
};

pair[] labelPos={
(65,77),
(192,62),
(374,115),
(375,220),
(143,143),
};

string[] labelTeX={
"$(X,T)$",
"$a$",
"$f(a)=0$",
"$f(F)=\{1\}$",
"$F$",
};

defaultpen(fontsize(10pt));

for(int i=0;i<labelTeX.length;++i){
  label(labelTeX[i],labelPos[i]);
}

guide gb=graph(pb,operator..)..cycle;
guide gc=graph(pc,operator..)..cycle;
guide garrow1=graph(parrow1,operator..);
guide garrow2=graph(parrow2,operator..);

pen fillPen=orange;
pen linePen=darkblue+1.2bp;

draw(gb,linePen);
filldraw(gc,fillPen,linePen);

real tickW=3bp;
draw(pspan[0]--pspan[1],linePen);

draw((pspan[0]-(0,tickW))--(pspan[0]+(0,tickW)),linePen);
draw((pspan[1]-(0,tickW))--(pspan[1]+(0,tickW)),linePen);

label("$0$",pspan[0]-(0,tickW),S);
label("$1$",pspan[1]-(0,tickW),S);

draw(garrow1,linePen,Arrow(HookHead,size=3));
filldraw(circle(parrow1[0],3bp),linePen);

draw(garrow2,linePen,Arrow(HookHead,size=3));

\end{asy}
\end{figure}
\end{document}

To process it with latexmk, create file latexmkrc:

sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");

and run latexmk -pdf diag.tex.

share|improve this answer
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.