Skip to content

Commit

Permalink
Add scaling option to plots (from plmaps)
Browse files Browse the repository at this point in the history
  • Loading branch information
DMRobertson committed Nov 22, 2017
1 parent 5bb8bd1 commit 2d3528b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions thompson/drawing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def display_file(filepath, format=None, scale=1.0, verbose=False):
raise NotImplementedError
return filepath

def plot(*auts, dest=None, display=True, diagonal=False, endpoints=False):
def plot(*auts, dest=None, display=True, diagonal=False, endpoints=False, scale=1):
r"""Plots the given :class:`automorphism <thompson.automorphism.Automorphism>` s as a function :math:`[0, 1] \to [0, 1]`. The image is rendered as an SVG using `svgwrite`.
:param str dest: the destination filepath to save the SVG to. If `None`, the SVG is saved to a temporary file location.
Expand All @@ -79,7 +79,7 @@ def plot(*auts, dest=None, display=True, diagonal=False, endpoints=False):
if dest is None:
#Write to a temporary file
dest = mkstemp()[1]
plot_svg(*auts, filename=dest, diagonal=diagonal, endpoints=endpoints)
plot_svg(*auts, filename=dest, diagonal=diagonal, endpoints=endpoints, display_scale=scale)

if display:
return display_file(dest, format='svg')
Expand Down
11 changes: 6 additions & 5 deletions thompson/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
PADDING = 40
SCALE = 400

def new_drawing(filename='plot.svg'):
def new_drawing(filename='plot.svg', display_scale=1):
from svgwrite.drawing import Drawing
from svgwrite.container import Group
size = 2 * PADDING + SCALE
dwg = Drawing(filename, size=(size, size))
dwg = Drawing(filename, size=(size * display_scale, size * display_scale))
dwg.viewbox(minx=0, miny=0, width=size, height=size)

add_stylesheet(dwg)
Expand Down Expand Up @@ -103,12 +103,12 @@ def draw_grid(canvas, signature, levels=None):
for line in lines[d]:
canvas.add(line)

def plot(*auts, filename='plot.svg', diagonal=True, endpoints=False):
def plot(*auts, filename='plot.svg', diagonal=True, endpoints=False, display_scale=1):
assert len({aut.signature for aut in auts}) == 1
from svgwrite.path import Path
from svgwrite.shapes import Line, Polyline
from svgwrite.container import Group
dwg, canvas = new_drawing(filename)
dwg, canvas = new_drawing(filename, display_scale)
include_markers(dwg, endpoints)
draw_grid(canvas, auts[0].signature)

Expand Down Expand Up @@ -139,4 +139,5 @@ def graph_segments(aut):
for d, r in zip(aut.domain, aut.range):
x0, x1 = (float(x) for x in d.as_interval())
y0, y1 = (float(y) for y in r.as_interval())
yield (x0, y0, x1, y1)
yield (x0, y0, x1, y1)

0 comments on commit 2d3528b

Please sign in to comment.