jeudi 4 décembre 2014

metapost annotation


Metapost is a powerful tool for drawing, but not sure if it's more easier than tikz for annotation. Is it possible to draw this annotation graph with metapost?


tikz code:



\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\tikzstyle{boxa} = [top color=white,bottom color=blue!20!]
\tikzstyle{boxb} = [top color=white,bottom color=red!20!]
\tikzstyle{curly} = [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=2pt]
% Input:
% #1 Line offset (optional)
% #2 Line angle
% #3 line start offset
% #4 Line end offset
% #5 Line label
% Example:
% \lineann[1]{30}{1}{4}{$L_1$}
\newcommand{\lineann}[5][0.5]{%
\begin{scope}[rotate=#2,blue,inner sep=2pt]
\draw[dashed, blue!40] (#3,0) -- +(0,#1)
node [coordinate, near end] (a) {};
\draw[dashed, blue!40] (#4,0) -- +(0,#1)
node [coordinate, near end] (b) {};
\draw[|<->|] (a) -- node[fill=white] {#5} (b);
\end{scope}
}
\begin{document}

\begin{tikzpicture}[scale=1]
\def\dx{2.0}
\def\dy{.5}
\filldraw[thick,boxa] (0,0) rectangle node{$P_1$} +(\dx,\dy);
\filldraw[thick,boxa] (\dx,0) rectangle node{$P_2$} +(\dx,\dy);
\filldraw[thick,boxa] (2*\dx,0) rectangle node{$P_3$} +(\dx,\dy);
\filldraw[thick,boxb] (3*\dx,0) rectangle node{$P_4$} +(\dx,\dy);

\draw [curly] (0,\dy)--(4*\dx,\dy) node [black,midway,yshift=14pt] {\footnotesize $T_0$};
\lineann[-10pt]{0}{3*\dx}{4*\dx}{\footnotesize $T_1$}
\end{tikzpicture}
\end{document}


Output:


enter image description here





Aucun commentaire:

Enregistrer un commentaire