# Ticket #12090: trac_12090-braid-plot.patch

File trac_12090-braid-plot.patch, 5.5 KB (added by ncohen, 8 years ago)
• ## doc/en/reference/plotting/index.rst

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1369405920 -7200
# Node ID 92d53613bc2d9ebcbca2c87323bf310339a759b9
# Parent  16768eaa774a10ee080f972ed1a80ab32baeaad9
Arrangements of pseudolines -- creation of sage.plot.braid_plot

diff --git a/doc/en/reference/plotting/index.rst b/doc/en/reference/plotting/index.rst```
 a sage/plot/colors sage/plot/hyperbolic_arc sage/plot/hyperbolic_triangle sage/plot/braid_plot .. include:: ../footer.txt
• ## sage/groups/braid.py

`diff --git a/sage/groups/braid.py b/sage/groups/braid.py`
 a per = per*Permutation(((j, j+1))) return per def plot(self, color='rainbow', orientation='bottom-top', gap=0.05, aspect_ratio=1, axes=False, **kwds): def plot(self, color='rainbow', orientation='bottom-top', gap=0.05, aspect_ratio=1, axes=False, **kwds): """ Plot the braid sage: b = t^-1*s^2 sage: b.plot(orientation="left-right", color="red") """ from sage.plot.bezier_path import bezier_path from sage.plot.plot import Graphics, line from sage.plot.colors import rainbow if orientation=='top-bottom': orx = 0 ory = -1 nx = 1 ny = 0 elif orientation=='left-right': orx = 1 ory = 0 nx = 0 ny = -1 elif orientation=='bottom-top': orx = 0 ory = 1 nx = 1 ny = 0 else: raise ValueError('unknown value for "orientation"') n = self.strands() if isinstance(color, (list, tuple)): if len(color) != n: raise TypeError("color (=%s) must contain exactly %d colors" % (color, n)) col = list(color) elif color == "rainbow": col = rainbow(n) else: col = [color]*n braid = self.Tietze() a = Graphics() op = gap for i, m in enumerate(braid): for j in range(n): if m==j+1: a += bezier_path([[(j*nx+i*orx, i*ory+j*ny), (j*nx+orx*(i+0.25), j*ny+ory*(i+0.25)), (nx*(j+0.5)+orx*(i+0.5), ny*(j+0.5)+ory*(i+0.5))], [(nx*(j+1)+orx*(i+0.75), ny*(j+1)+ory*(i+0.75)), (nx*(j+1)+orx*(i+1), ny*(j+1)+ory*(i+1))]], color=col[j], **kwds) elif m==j: a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), (nx*(j-0.5+4*op)+orx*(i+0.5-2*op), ny*(j-0.5+4*op)+ory*(i+0.5-2*op)), (nx*(j-0.5+2*op)+orx*(i+0.5-op), ny*(j-0.5+2*op)+ory*(i+0.5-op))]], color=col[j], **kwds) a += bezier_path([[(nx*(j-0.5-2*op)+orx*(i+0.5+op), ny*(j-0.5-2*op)+ory*(i+0.5+op)), (nx*(j-0.5-4*op)+orx*(i+0.5+2*op), ny*(j-0.5-4*op)+ory*(i+0.5+2*op)), (nx*(j-1)+orx*(i+0.75), ny*(j-1)+ory*(i+0.75)), (nx*(j-1)+orx*(i+1), ny*(j-1)+ory*(i+1))]], color=col[j], **kwds) col[j], col[j-1] = col[j-1], col[j] elif -m==j+1: a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), (nx*(j+0.5-4*op)+orx*(i+0.5-2*op), ny*(j+0.5-4*op)+ory*(i+0.5-2*op)), (nx*(j+0.5-2*op)+orx*(i+0.5-op), ny*(j+0.5-2*op)+ory*(i+0.5-op))]], color=col[j], **kwds) a += bezier_path([[(nx*(j+0.5+2*op)+orx*(i+0.5+op), ny*(j+0.5+2*op)+ory*(i+0.5+op)), (nx*(j+0.5+4*op)+orx*(i+0.5+2*op), ny*(j+0.5+4*op)+ory*(i+0.5+2*op)), (nx*(j+1)+orx*(i+0.75), ny*(j+1)+ory*(i+0.75)), (nx*(j+1)+orx*(i+1), ny*(j+1)+ory*(i+1))]], color=col[j], **kwds) elif -m==j: a += bezier_path([[(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+0.25), ny*j+ory*(i+0.25)), (nx*(j-0.5)+orx*(i+0.5), ny*(j-0.5)+ory*(i+0.5))], [(nx*(j-1)+orx*(i+0.75), ny*(j-1)+ory*(i+0.75)), (nx*(j-1)+orx*(i+1), ny*(j-1)+ory*(i+1))]], color=col[j], **kwds) col[j], col[j-1] = col[j-1], col[j] else: a += line([(nx*j+orx*i, ny*j+ory*i), (nx*j+orx*(i+1), ny*j+ory*(i+1))], color=col[j], **kwds) a.set_aspect_ratio(aspect_ratio) a.axes(axes) return a from sage.plot.braid_plot import braid_plot return braid_plot(self.Tietze(), color=color, orientation=orientation, gap=gap, aspect_ratio=aspect_ratio, axes=axes, **kwds) def plot3d(self, color='rainbow'): """
• ## sage/plot/all.py

`diff --git a/sage/plot/all.py b/sage/plot/all.py`
 a from hyperbolic_arc import hyperbolic_arc from hyperbolic_triangle import hyperbolic_triangle import sage.plot.braid_plot