Using Tikzmagic

TIKZ is a great language for producing vector graphics. It is however a bit tedious to go over the whole $\LaTeX$-like compilation when you get used to an ipython notebooks work-flow.

I describe here how to use a cell magic implemented by http://www2.ipp.mpg.de/~mkraus/python/tikzmagic.py and a hack to use euclide within the graph (as implemented in https://github.com/laurentperrinet/ipython_magics).

Installation

In [1]:
%install_ext https://raw.githubusercontent.com/laurentperrinet/ipython_magics/master/tikzmagic.py
Installed tikzmagic.py. To use it, type:
  %load_ext tikzmagic
/usr/local/lib/python3.5/site-packages/IPython/core/magics/extension.py:47: UserWarning: %install_ext` is deprecated, please distribute your extension(s)as a python packages.
  "as a python packages.", UserWarning)
In [2]:
%load_ext tikzmagic

### basic usage
In [3]:
%tikz \draw (0,0) rectangle (1,1);
No description has been provided for this image
In [4]:
%%tikz -s 400,400 -sc 1.2 -f png
\draw [style=help lines, step=2]				(-1,-1)	grid		(+7,+7);
\draw [line width=0.5mm, fill=blue!40!white]	(+2,+2)	rectangle	(+4,+4);
 
\draw [blue!60!white] (  2,  2) node[anchor=north east] {$(i  ,j  )$};
\draw [blue!60!white] (  4,  2) node[anchor=north west] {$(i+1,j  )$};
\draw [blue!60!white] (  4,  4) node[anchor=south west] {$(i+1,j+1)$};
\draw [blue!60!white] (  2,  4) node[anchor=south east] {$(i  ,j+1)$};

\filldraw [color=gray]	(0,0) circle (.1);
\filldraw [color=gray]	(0,2) circle (.1);
\filldraw [color=gray]	(0,4) circle (.1);
\filldraw [color=gray]	(0,6) circle (.1);
\filldraw [color=gray]	(2,0) circle (.1);
\filldraw [color=black]	(2,2) circle (.1);
\filldraw [color=black]	(2,4) circle (.1);
\filldraw [color=gray]	(2,6) circle (.1);
\filldraw [color=gray]	(4,0) circle (.1);
\filldraw [color=black]	(4,2) circle (.1);
\filldraw [color=black]	(4,4) circle (.1);
\filldraw [color=gray]	(4,6) circle (.1);
\filldraw [color=gray]	(6,0) circle (.1);
\filldraw [color=gray]	(6,2) circle (.1);
\filldraw [color=gray]	(6,4) circle (.1);
\filldraw [color=gray]	(6,6) circle (.1);
No description has been provided for this image

now with euclide

In [5]:
%%tikz -s 800,400 -sc 1.2 -f png

\tkzInit[xmax=13, ymax=8]

\tkzDefPoint(2.95, 2.25){A}
\tkzDefPoint(11,5.25){B}
\tkzLabelPoints[above left](A,B)
\tkzDefPoint(10, 2.25){C}

% draw red dots at the center of edges
\tkzDrawPoints[size=10, color=red, fill=red](A,B)


%----------------------------------------------------------
% Drawing the lines and segments
%----------------------------------------------------------
\tkzDrawLine[color=red,line width=2pt, add=-1.15 and -.15 ](C,A)
\tkzDrawLine[color=red,line width=2pt, add=-1.3 and -.3 ](C,B)

\tkzDrawLine(A,B)
\tkzDrawLines[dashed](A,C B,C)

% drawing arcs for angles  
\tkzMarkAngle[size=2.5,mkpos=.2](C,A,B)
\tkzLabelAngle[pos=3.5,circle](C,A,B){$\mathsf{\phi}$}

\tkzDefPointWith[linear,K=1.5](A,C)
\tkzGetPoint{D}
\tkzDefPointWith[linear,K=.75](B,C)
\tkzGetPoint{E}
\tkzMarkAngle[size=1,mkpos=.2](D,C,E)
\tkzLabelAngle[pos=1.75,circle](D,C,E){$\mathsf{\theta}$}
No description has been provided for this image

To crop the image, I use the \pgfresetboundingbox directive

In [6]:
%%tikz -s 800,400 -sc 1.2 -f png

\tkzInit[xmax=13, ymax=8]

\tkzDefPoint(2.95, 2.25){A}
\tkzDefPoint(11,5.25){B}
\tkzLabelPoints[above left](A,B)
\tkzDefPoint(10, 2.25){C}

% draw red dots at the center of edges
\tkzDrawPoints[size=10, color=red, fill=red](A,B)


%----------------------------------------------------------
% Drawing the lines and segments
%----------------------------------------------------------
\tkzDrawLine[color=red,line width=2pt, add=-1.15 and -.15 ](C,A)
\tkzDrawLine[color=red,line width=2pt, add=-1.3 and -.3 ](C,B)

\tkzDrawLine(A,B)
\tkzDrawLines[dashed](A,C B,C)

% drawing arcs for angles  
\tkzMarkAngle[size=2.5,mkpos=.2](C,A,B)
\tkzLabelAngle[pos=3.5,circle](C,A,B){$\mathsf{\phi}$}

\tkzDefPointWith[linear,K=1.5](A,C)
\tkzGetPoint{D}
\tkzDefPointWith[linear,K=.75](B,C)
\tkzGetPoint{E}
\tkzMarkAngle[size=1,mkpos=.2](D,C,E)
\tkzLabelAngle[pos=1.75,circle](D,C,E){$\mathsf{\theta}$}


\pgfresetboundingbox
\path(5, 1) rectangle (13, 8);
No description has been provided for this image

My full diagram

with as an option, a way to save it in SVG format:

In [7]:
%%tikz -f svg -s 800,500 --save /tmp/diagram.svg

%\fill[white,fill opacity=.9] (0, 1.2) rectangle (13, 8);
%\tkzInit[xmax=13, ymax=8]

%----------------------------------------------------------
% Defining coordinates
%----------------------------------------------------------

\tkzDefPoint(2.95, 2.25){A}
\tkzDefPoint(11,5.25){B}
\tkzLabelPoints[above left](A,B)
%   \tkzLabelPoints[below right](B)
\tkzDefPoint(10, 2.25){C}

% draw red dots at the center of edges
\tkzDrawPoints[size=10, color=red, fill=red](A,B)

%----------------------------------------------------------
% Drawing the lines and segments
%----------------------------------------------------------
\tkzDrawLine[color=red,line width=2pt, add=-1.15 and -.15 ](C,A)
\tkzDrawLine[color=red,line width=2pt, add=-1.3 and -.3 ](C,B)

\tkzDrawLine(A,B)
\tkzDrawLines[dashed](A,C B,C)

% drawing arcs for angles  
\tkzMarkAngle[size=2.5,mkpos=.2](C,A,B)
\tkzLabelAngle[pos=3.5,circle](C,A,B){$\mathsf{\phi}$}

\tkzDefPointWith[linear,K=1.5](A,C)
\tkzGetPoint{D}
\tkzDefPointWith[linear,K=.75](B,C)
\tkzGetPoint{E}
\tkzMarkAngle[size=1,mkpos=.2](D,C,E)
\tkzLabelAngle[pos=1.75,circle](D,C,E){$\mathsf{\theta}$}

%----------------------------------------------------------
% Drawing normals
%----------------------------------------------------------

\tkzDefLine[perpendicular=through A, K=-.75](C,A)
\tkzGetPoint{a1}
\tkzDefLine[perpendicular=through B, K=2.5](C,B)
\tkzGetPoint{b1}
\tkzInterLL(a1,A)(b1,B)  \tkzGetPoint{H}
\tkzMarkRightAngle[size=.5](H,A,C)
\tkzMarkRightAngle[size=.5](H,B,C)
\tkzDrawLines[dashed,dash phase=1.5pt](a1,A)
\tkzDrawLines[dashed,dash phase=0.5pt](b1,B)

%----------------------------------------------------------
% Drawing mediator and psi line
%----------------------------------------------------------
%    \tkzDefLine[mediator](A,B)          \tkzGetPoints{m1}{M}
\tkzDefMidPoint(A,B)
\tkzGetPoint{M}
\tkzDefLine[perpendicular=through M, K=.4](A,B)
\tkzGetPoint{m1}
\tkzMarkRightAngle[size=.5](B,M,m1)    

\tkzFillAngle[size=1.4,fill=blue!40](m1,M,H)
\tkzLabelAngle[pos=2,circle](m1,M,H){$\mathsf{\psi}$}%= \phi -\theta/2
\tkzDrawLines[](m1,M M,H)    

\pgfresetboundingbox
\path(1, 1) rectangle (13, 9);
<svg height="500px" version="1.1" viewBox="0 0 340.157 226.772" width="800px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <g> <symbol id="glyph0-0" overflow="visible"> <path d="" style="stroke:none;"/> </symbol> <symbol id="glyph0-1" overflow="visible"> <path d="M 1.78125 -1.140625 C 1.390625 -0.484375 1 -0.34375 0.5625 -0.3125 C 0.4375 -0.296875 0.34375 -0.296875 0.34375 -0.109375 C 0.34375 -0.046875 0.40625 0 0.484375 0 C 0.75 0 1.0625 -0.03125 1.328125 -0.03125 C 1.671875 -0.03125 2.015625 0 2.328125 0 C 2.390625 0 2.515625 0 2.515625 -0.1875 C 2.515625 -0.296875 2.4375 -0.3125 2.359375 -0.3125 C 2.140625 -0.328125 1.890625 -0.40625 1.890625 -0.65625 C 1.890625 -0.78125 1.953125 -0.890625 2.03125 -1.03125 L 2.796875 -2.296875 L 5.296875 -2.296875 C 5.3125 -2.09375 5.453125 -0.734375 5.453125 -0.640625 C 5.453125 -0.34375 4.9375 -0.3125 4.734375 -0.3125 C 4.59375 -0.3125 4.5 -0.3125 4.5 -0.109375 C 4.5 0 4.609375 0 4.640625 0 C 5.046875 0 5.46875 -0.03125 5.875 -0.03125 C 6.125 -0.03125 6.765625 0 7.015625 0 C 7.0625 0 7.1875 0 7.1875 -0.203125 C 7.1875 -0.3125 7.09375 -0.3125 6.953125 -0.3125 C 6.34375 -0.3125 6.34375 -0.375 6.3125 -0.671875 L 5.703125 -6.890625 C 5.6875 -7.09375 5.6875 -7.140625 5.515625 -7.140625 C 5.359375 -7.140625 5.3125 -7.0625 5.25 -6.96875 Z M 2.984375 -2.609375 L 4.9375 -5.90625 L 5.265625 -2.609375 Z M 2.984375 -2.609375 " style="stroke:none;"/> </symbol> <symbol id="glyph0-2" overflow="visible"> <path d="M 1.59375 -0.78125 C 1.5 -0.390625 1.46875 -0.3125 0.6875 -0.3125 C 0.515625 -0.3125 0.421875 -0.3125 0.421875 -0.109375 C 0.421875 0 0.515625 0 0.6875 0 L 4.25 0 C 5.828125 0 7 -1.171875 7 -2.15625 C 7 -2.875 6.421875 -3.453125 5.453125 -3.5625 C 6.484375 -3.75 7.53125 -4.484375 7.53125 -5.4375 C 7.53125 -6.171875 6.875 -6.8125 5.6875 -6.8125 L 2.328125 -6.8125 C 2.140625 -6.8125 2.046875 -6.8125 2.046875 -6.609375 C 2.046875 -6.5 2.140625 -6.5 2.328125 -6.5 C 2.34375 -6.5 2.53125 -6.5 2.703125 -6.484375 C 2.875 -6.453125 2.96875 -6.453125 2.96875 -6.3125 C 2.96875 -6.28125 2.953125 -6.25 2.9375 -6.125 Z M 3.09375 -3.65625 L 3.71875 -6.125 C 3.8125 -6.46875 3.828125 -6.5 4.25 -6.5 L 5.546875 -6.5 C 6.421875 -6.5 6.625 -5.90625 6.625 -5.46875 C 6.625 -4.59375 5.765625 -3.65625 4.5625 -3.65625 Z M 2.65625 -0.3125 C 2.515625 -0.3125 2.5 -0.3125 2.4375 -0.3125 C 2.328125 -0.328125 2.296875 -0.34375 2.296875 -0.421875 C 2.296875 -0.453125 2.296875 -0.46875 2.359375 -0.640625 L 3.046875 -3.421875 L 4.921875 -3.421875 C 5.875 -3.421875 6.078125 -2.6875 6.078125 -2.265625 C 6.078125 -1.28125 5.1875 -0.3125 4 -0.3125 Z M 2.65625 -0.3125 " style="stroke:none;"/> </symbol> <symbol id="glyph0-3" overflow="visible"> <path d="M 4.359375 -6.671875 C 4.359375 -6.703125 4.390625 -6.8125 4.390625 -6.8125 C 4.390625 -6.828125 4.390625 -6.921875 4.265625 -6.921875 C 4.171875 -6.921875 4.15625 -6.890625 4.109375 -6.71875 L 3.53125 -4.421875 C 1.953125 -4.359375 0.484375 -3.046875 0.484375 -1.6875 C 0.484375 -0.734375 1.1875 0.046875 2.40625 0.125 C 2.328125 0.421875 2.25 0.75 2.171875 1.0625 C 2.046875 1.53125 1.953125 1.90625 1.953125 1.9375 C 1.953125 2.03125 2.03125 2.046875 2.078125 2.046875 C 2.125 2.046875 2.140625 2.03125 2.171875 2 C 2.1875 1.984375 2.25 1.75 2.28125 1.609375 L 2.65625 0.125 C 4.265625 0.0625 5.71875 -1.28125 5.71875 -2.609375 C 5.71875 -3.40625 5.1875 -4.3125 3.796875 -4.421875 Z M 2.453125 -0.09375 C 1.859375 -0.125 1.140625 -0.484375 1.140625 -1.46875 C 1.140625 -2.671875 2 -4.0625 3.484375 -4.203125 Z M 3.734375 -4.203125 C 4.5 -4.15625 5.0625 -3.703125 5.0625 -2.828125 C 5.0625 -1.640625 4.203125 -0.21875 2.71875 -0.09375 Z M 3.734375 -4.203125 " style="stroke:none;"/> </symbol> <symbol id="glyph0-4" overflow="visible"> <path d="M 4.53125 -4.984375 C 4.53125 -5.640625 4.359375 -7.03125 3.34375 -7.03125 C 1.953125 -7.03125 0.421875 -4.21875 0.421875 -1.9375 C 0.421875 -1 0.703125 0.109375 1.609375 0.109375 C 3.015625 0.109375 4.53125 -2.75 4.53125 -4.984375 Z M 1.46875 -3.625 C 1.640625 -4.25 1.84375 -5.046875 2.25 -5.765625 C 2.515625 -6.25 2.875 -6.8125 3.328125 -6.8125 C 3.8125 -6.8125 3.875 -6.171875 3.875 -5.609375 C 3.875 -5.109375 3.796875 -4.609375 3.5625 -3.625 Z M 3.46875 -3.296875 C 3.359375 -2.84375 3.15625 -2 2.765625 -1.28125 C 2.421875 -0.59375 2.046875 -0.109375 1.609375 -0.109375 C 1.28125 -0.109375 1.078125 -0.40625 1.078125 -1.328125 C 1.078125 -1.75 1.140625 -2.328125 1.390625 -3.296875 Z M 3.46875 -3.296875 " style="stroke:none;"/> </symbol> <symbol id="glyph0-5" overflow="visible"> <path d="M 4.8125 -6.65625 C 4.8125 -6.703125 4.828125 -6.765625 4.828125 -6.8125 C 4.828125 -6.90625 4.765625 -6.921875 4.71875 -6.921875 C 4.609375 -6.921875 4.609375 -6.890625 4.5625 -6.71875 L 2.90625 -0.125 C 2.15625 -0.21875 1.78125 -0.59375 1.78125 -1.25 C 1.78125 -1.453125 1.78125 -1.703125 2.3125 -3.09375 C 2.359375 -3.21875 2.421875 -3.390625 2.421875 -3.59375 C 2.421875 -4.03125 2.109375 -4.40625 1.609375 -4.40625 C 0.65625 -4.40625 0.296875 -2.953125 0.296875 -2.875 C 0.296875 -2.765625 0.390625 -2.765625 0.40625 -2.765625 C 0.515625 -2.765625 0.515625 -2.796875 0.5625 -2.953125 C 0.84375 -3.890625 1.234375 -4.1875 1.578125 -4.1875 C 1.65625 -4.1875 1.828125 -4.1875 1.828125 -3.875 C 1.828125 -3.609375 1.71875 -3.359375 1.59375 -3.015625 C 1.109375 -1.75 1.109375 -1.5 1.109375 -1.328125 C 1.109375 -0.375 1.890625 0.03125 2.84375 0.09375 C 2.765625 0.453125 2.765625 0.46875 2.625 1 C 2.609375 1.109375 2.40625 1.90625 2.40625 1.9375 C 2.40625 1.953125 2.40625 2.046875 2.515625 2.046875 C 2.546875 2.046875 2.59375 2.046875 2.609375 2 C 2.640625 1.984375 2.703125 1.734375 2.734375 1.59375 L 3.109375 0.109375 C 3.484375 0.109375 4.359375 0.109375 5.296875 -0.953125 C 5.703125 -1.421875 5.90625 -1.859375 6.015625 -2.15625 C 6.109375 -2.40625 6.328125 -3.265625 6.328125 -3.703125 C 6.328125 -4.265625 6.0625 -4.40625 5.890625 -4.40625 C 5.640625 -4.40625 5.390625 -4.140625 5.390625 -3.921875 C 5.390625 -3.796875 5.453125 -3.734375 5.546875 -3.65625 C 5.65625 -3.546875 5.90625 -3.296875 5.90625 -2.8125 C 5.90625 -2.171875 5.390625 -1.359375 5.03125 -1 C 4.15625 -0.109375 3.515625 -0.109375 3.15625 -0.109375 Z M 4.8125 -6.65625 " style="stroke:none;"/> </symbol> </g> </defs> <g id="surface1"> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="44.284" xlink:href="#glyph0-1" y="187.819"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="271.888" xlink:href="#glyph0-2" y="102.78"/> </g> <path d="M 85.615531 63.782062 C 85.615531 64.879719 84.724906 65.77425 83.623344 65.77425 C 82.521781 65.77425 81.631156 64.879719 81.631156 63.782062 C 81.631156 62.6805 82.521781 61.785969 83.623344 61.785969 C 84.724906 61.785969 85.615531 62.6805 85.615531 63.782062 Z M 85.615531 63.782062 " style="fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 313.806938 148.821125 C 313.806938 149.922687 312.916313 150.813312 311.81475 150.813312 C 310.713188 150.813312 309.822563 149.922687 309.822563 148.821125 C 309.822563 147.719562 310.713188 146.828937 311.81475 146.828937 C 312.916313 146.828937 313.806938 147.719562 313.806938 148.821125 Z M 313.806938 148.821125 " style="fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 53.646781 63.782062 L 113.599906 63.782062 " style="fill:none;stroke-width:1.99255;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 320.318656 174.332844 L 303.310844 123.309406 " style="fill:none;stroke-width:1.99255;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 37.986625 46.77425 L 357.451469 165.828937 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 43.654594 63.782062 L 323.435844 63.782062 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 317.482719 165.828937 L 277.799125 46.77425 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 154.490531 63.782062 C 154.490531 72.21175 152.978813 80.582844 150.041313 88.485187 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="149.949" xlink:href="#glyph0-3" y="176.258"/> </g> <path d="M 311.81475 63.782062 C 311.81475 75.985187 304.00225 86.817219 292.424125 90.672687 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="292.878" xlink:href="#glyph0-4" y="165.789"/> </g> <path d="M 83.623344 63.782062 L 83.623344 77.953937 L 97.795219 77.953937 L 97.795219 63.782062 Z M 83.623344 63.782062 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 311.81475 148.821125 L 298.369438 153.301594 L 293.888969 139.856281 L 307.334281 135.375812 Z M 311.81475 148.821125 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 83.623344 243.641437 L 83.623344 33.8055 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-dashoffset:1.49442;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 56.693656 233.860187 L 354.334281 134.64925 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-dashoffset:0.49814;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 197.717094 106.301594 L 210.998344 111.250812 L 206.049125 124.532062 L 192.767875 119.582844 Z M 197.717094 106.301594 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 169.371094 148.816406 L 155.503906 111.636719 C 150.421875 113.53125 145.773438 116.457031 141.859375 120.21875 Z M 169.371094 148.816406 " style=" stroke:none;fill-rule:nonzero;fill:rgb(59.999084%,59.999084%,100%);fill-opacity:1;"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="135.76" xlink:href="#glyph0-5" y="103.324"/> </g> <path d="M 156.900688 215.828937 L 204.521781 88.043781 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 220.537406 82.582844 L 60.803031 248.602375 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> </g> </svg>
In [8]:
from IPython.display import Image, SVG
SVG(filename="/tmp/diagram.svg")
Out[8]:
<svg height="226.772pt" version="1.1" viewBox="0 0 340.157 226.772" width="340.157pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <g> <symbol id="glyph0-0" overflow="visible"> <path d="" style="stroke:none;"/> </symbol> <symbol id="glyph0-1" overflow="visible"> <path d="M 1.78125 -1.140625 C 1.390625 -0.484375 1 -0.34375 0.5625 -0.3125 C 0.4375 -0.296875 0.34375 -0.296875 0.34375 -0.109375 C 0.34375 -0.046875 0.40625 0 0.484375 0 C 0.75 0 1.0625 -0.03125 1.328125 -0.03125 C 1.671875 -0.03125 2.015625 0 2.328125 0 C 2.390625 0 2.515625 0 2.515625 -0.1875 C 2.515625 -0.296875 2.4375 -0.3125 2.359375 -0.3125 C 2.140625 -0.328125 1.890625 -0.40625 1.890625 -0.65625 C 1.890625 -0.78125 1.953125 -0.890625 2.03125 -1.03125 L 2.796875 -2.296875 L 5.296875 -2.296875 C 5.3125 -2.09375 5.453125 -0.734375 5.453125 -0.640625 C 5.453125 -0.34375 4.9375 -0.3125 4.734375 -0.3125 C 4.59375 -0.3125 4.5 -0.3125 4.5 -0.109375 C 4.5 0 4.609375 0 4.640625 0 C 5.046875 0 5.46875 -0.03125 5.875 -0.03125 C 6.125 -0.03125 6.765625 0 7.015625 0 C 7.0625 0 7.1875 0 7.1875 -0.203125 C 7.1875 -0.3125 7.09375 -0.3125 6.953125 -0.3125 C 6.34375 -0.3125 6.34375 -0.375 6.3125 -0.671875 L 5.703125 -6.890625 C 5.6875 -7.09375 5.6875 -7.140625 5.515625 -7.140625 C 5.359375 -7.140625 5.3125 -7.0625 5.25 -6.96875 Z M 2.984375 -2.609375 L 4.9375 -5.90625 L 5.265625 -2.609375 Z M 2.984375 -2.609375 " style="stroke:none;"/> </symbol> <symbol id="glyph0-2" overflow="visible"> <path d="M 1.59375 -0.78125 C 1.5 -0.390625 1.46875 -0.3125 0.6875 -0.3125 C 0.515625 -0.3125 0.421875 -0.3125 0.421875 -0.109375 C 0.421875 0 0.515625 0 0.6875 0 L 4.25 0 C 5.828125 0 7 -1.171875 7 -2.15625 C 7 -2.875 6.421875 -3.453125 5.453125 -3.5625 C 6.484375 -3.75 7.53125 -4.484375 7.53125 -5.4375 C 7.53125 -6.171875 6.875 -6.8125 5.6875 -6.8125 L 2.328125 -6.8125 C 2.140625 -6.8125 2.046875 -6.8125 2.046875 -6.609375 C 2.046875 -6.5 2.140625 -6.5 2.328125 -6.5 C 2.34375 -6.5 2.53125 -6.5 2.703125 -6.484375 C 2.875 -6.453125 2.96875 -6.453125 2.96875 -6.3125 C 2.96875 -6.28125 2.953125 -6.25 2.9375 -6.125 Z M 3.09375 -3.65625 L 3.71875 -6.125 C 3.8125 -6.46875 3.828125 -6.5 4.25 -6.5 L 5.546875 -6.5 C 6.421875 -6.5 6.625 -5.90625 6.625 -5.46875 C 6.625 -4.59375 5.765625 -3.65625 4.5625 -3.65625 Z M 2.65625 -0.3125 C 2.515625 -0.3125 2.5 -0.3125 2.4375 -0.3125 C 2.328125 -0.328125 2.296875 -0.34375 2.296875 -0.421875 C 2.296875 -0.453125 2.296875 -0.46875 2.359375 -0.640625 L 3.046875 -3.421875 L 4.921875 -3.421875 C 5.875 -3.421875 6.078125 -2.6875 6.078125 -2.265625 C 6.078125 -1.28125 5.1875 -0.3125 4 -0.3125 Z M 2.65625 -0.3125 " style="stroke:none;"/> </symbol> <symbol id="glyph0-3" overflow="visible"> <path d="M 4.359375 -6.671875 C 4.359375 -6.703125 4.390625 -6.8125 4.390625 -6.8125 C 4.390625 -6.828125 4.390625 -6.921875 4.265625 -6.921875 C 4.171875 -6.921875 4.15625 -6.890625 4.109375 -6.71875 L 3.53125 -4.421875 C 1.953125 -4.359375 0.484375 -3.046875 0.484375 -1.6875 C 0.484375 -0.734375 1.1875 0.046875 2.40625 0.125 C 2.328125 0.421875 2.25 0.75 2.171875 1.0625 C 2.046875 1.53125 1.953125 1.90625 1.953125 1.9375 C 1.953125 2.03125 2.03125 2.046875 2.078125 2.046875 C 2.125 2.046875 2.140625 2.03125 2.171875 2 C 2.1875 1.984375 2.25 1.75 2.28125 1.609375 L 2.65625 0.125 C 4.265625 0.0625 5.71875 -1.28125 5.71875 -2.609375 C 5.71875 -3.40625 5.1875 -4.3125 3.796875 -4.421875 Z M 2.453125 -0.09375 C 1.859375 -0.125 1.140625 -0.484375 1.140625 -1.46875 C 1.140625 -2.671875 2 -4.0625 3.484375 -4.203125 Z M 3.734375 -4.203125 C 4.5 -4.15625 5.0625 -3.703125 5.0625 -2.828125 C 5.0625 -1.640625 4.203125 -0.21875 2.71875 -0.09375 Z M 3.734375 -4.203125 " style="stroke:none;"/> </symbol> <symbol id="glyph0-4" overflow="visible"> <path d="M 4.53125 -4.984375 C 4.53125 -5.640625 4.359375 -7.03125 3.34375 -7.03125 C 1.953125 -7.03125 0.421875 -4.21875 0.421875 -1.9375 C 0.421875 -1 0.703125 0.109375 1.609375 0.109375 C 3.015625 0.109375 4.53125 -2.75 4.53125 -4.984375 Z M 1.46875 -3.625 C 1.640625 -4.25 1.84375 -5.046875 2.25 -5.765625 C 2.515625 -6.25 2.875 -6.8125 3.328125 -6.8125 C 3.8125 -6.8125 3.875 -6.171875 3.875 -5.609375 C 3.875 -5.109375 3.796875 -4.609375 3.5625 -3.625 Z M 3.46875 -3.296875 C 3.359375 -2.84375 3.15625 -2 2.765625 -1.28125 C 2.421875 -0.59375 2.046875 -0.109375 1.609375 -0.109375 C 1.28125 -0.109375 1.078125 -0.40625 1.078125 -1.328125 C 1.078125 -1.75 1.140625 -2.328125 1.390625 -3.296875 Z M 3.46875 -3.296875 " style="stroke:none;"/> </symbol> <symbol id="glyph0-5" overflow="visible"> <path d="M 4.8125 -6.65625 C 4.8125 -6.703125 4.828125 -6.765625 4.828125 -6.8125 C 4.828125 -6.90625 4.765625 -6.921875 4.71875 -6.921875 C 4.609375 -6.921875 4.609375 -6.890625 4.5625 -6.71875 L 2.90625 -0.125 C 2.15625 -0.21875 1.78125 -0.59375 1.78125 -1.25 C 1.78125 -1.453125 1.78125 -1.703125 2.3125 -3.09375 C 2.359375 -3.21875 2.421875 -3.390625 2.421875 -3.59375 C 2.421875 -4.03125 2.109375 -4.40625 1.609375 -4.40625 C 0.65625 -4.40625 0.296875 -2.953125 0.296875 -2.875 C 0.296875 -2.765625 0.390625 -2.765625 0.40625 -2.765625 C 0.515625 -2.765625 0.515625 -2.796875 0.5625 -2.953125 C 0.84375 -3.890625 1.234375 -4.1875 1.578125 -4.1875 C 1.65625 -4.1875 1.828125 -4.1875 1.828125 -3.875 C 1.828125 -3.609375 1.71875 -3.359375 1.59375 -3.015625 C 1.109375 -1.75 1.109375 -1.5 1.109375 -1.328125 C 1.109375 -0.375 1.890625 0.03125 2.84375 0.09375 C 2.765625 0.453125 2.765625 0.46875 2.625 1 C 2.609375 1.109375 2.40625 1.90625 2.40625 1.9375 C 2.40625 1.953125 2.40625 2.046875 2.515625 2.046875 C 2.546875 2.046875 2.59375 2.046875 2.609375 2 C 2.640625 1.984375 2.703125 1.734375 2.734375 1.59375 L 3.109375 0.109375 C 3.484375 0.109375 4.359375 0.109375 5.296875 -0.953125 C 5.703125 -1.421875 5.90625 -1.859375 6.015625 -2.15625 C 6.109375 -2.40625 6.328125 -3.265625 6.328125 -3.703125 C 6.328125 -4.265625 6.0625 -4.40625 5.890625 -4.40625 C 5.640625 -4.40625 5.390625 -4.140625 5.390625 -3.921875 C 5.390625 -3.796875 5.453125 -3.734375 5.546875 -3.65625 C 5.65625 -3.546875 5.90625 -3.296875 5.90625 -2.8125 C 5.90625 -2.171875 5.390625 -1.359375 5.03125 -1 C 4.15625 -0.109375 3.515625 -0.109375 3.15625 -0.109375 Z M 4.8125 -6.65625 " style="stroke:none;"/> </symbol> </g> </defs> <g id="surface1"> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="44.284" xlink:href="#glyph0-1" y="187.819"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="271.888" xlink:href="#glyph0-2" y="102.78"/> </g> <path d="M 85.615531 63.782062 C 85.615531 64.879719 84.724906 65.77425 83.623344 65.77425 C 82.521781 65.77425 81.631156 64.879719 81.631156 63.782062 C 81.631156 62.6805 82.521781 61.785969 83.623344 61.785969 C 84.724906 61.785969 85.615531 62.6805 85.615531 63.782062 Z M 85.615531 63.782062 " style="fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 313.806938 148.821125 C 313.806938 149.922687 312.916313 150.813312 311.81475 150.813312 C 310.713188 150.813312 309.822563 149.922687 309.822563 148.821125 C 309.822563 147.719562 310.713188 146.828937 311.81475 146.828937 C 312.916313 146.828937 313.806938 147.719562 313.806938 148.821125 Z M 313.806938 148.821125 " style="fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 53.646781 63.782062 L 113.599906 63.782062 " style="fill:none;stroke-width:1.99255;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 320.318656 174.332844 L 303.310844 123.309406 " style="fill:none;stroke-width:1.99255;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 37.986625 46.77425 L 357.451469 165.828937 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 43.654594 63.782062 L 323.435844 63.782062 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 317.482719 165.828937 L 277.799125 46.77425 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 154.490531 63.782062 C 154.490531 72.21175 152.978813 80.582844 150.041313 88.485187 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="149.949" xlink:href="#glyph0-3" y="176.258"/> </g> <path d="M 311.81475 63.782062 C 311.81475 75.985187 304.00225 86.817219 292.424125 90.672687 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="292.878" xlink:href="#glyph0-4" y="165.789"/> </g> <path d="M 83.623344 63.782062 L 83.623344 77.953937 L 97.795219 77.953937 L 97.795219 63.782062 Z M 83.623344 63.782062 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 311.81475 148.821125 L 298.369438 153.301594 L 293.888969 139.856281 L 307.334281 135.375812 Z M 311.81475 148.821125 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 83.623344 243.641437 L 83.623344 33.8055 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-dashoffset:1.49442;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 56.693656 233.860187 L 354.334281 134.64925 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-dasharray:2.98883,2.98883;stroke-dashoffset:0.49814;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 197.717094 106.301594 L 210.998344 111.250812 L 206.049125 124.532062 L 192.767875 119.582844 Z M 197.717094 106.301594 " style="fill:none;stroke-width:0.3985;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 169.371094 148.816406 L 155.503906 111.636719 C 150.421875 113.53125 145.773438 116.457031 141.859375 120.21875 Z M 169.371094 148.816406 " style=" stroke:none;fill-rule:nonzero;fill:rgb(59.999084%,59.999084%,100%);fill-opacity:1;"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use x="135.76" xlink:href="#glyph0-5" y="103.324"/> </g> <path d="M 156.900688 215.828937 L 204.521781 88.043781 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> <path d="M 220.537406 82.582844 L 60.803031 248.602375 " style="fill:none;stroke-width:0.59776;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" transform="matrix(1,0,0,-1,-28.346,255.118)"/> </g> </svg>

Beautiful!