From 78c47d22eb97d5a65a4747a92ee49534282af37a Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 3 Jun 2017 21:04:08 -0500 Subject: [PATCH 1/2] draw_arrow(): Fix length by scaling with the width the of plot. (closes #20) --- sumpy/toys.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sumpy/toys.py b/sumpy/toys.py index d61af4fa..562d570d 100644 --- a/sumpy/toys.py +++ b/sumpy/toys.py @@ -540,8 +540,11 @@ class SchematicVisitor(object): verticalalignment='center', horizontalalignment='center') if psource.derived_from is not None: + xmin, xmax = plt.xlim() + plt_width = xmax - xmin draw_arrow(psource.derived_from.center, psource.center, shorten=0.1, - facecolor="black", length_includes_head=True, width=0.02) + facecolor="black", length_includes_head=True, + width=0.0005 * plt_width) self.rec(psource.derived_from) visit_localexpansion = visit_multipoleexpansion -- GitLab From e680fe2ab9d1b6d3296dd6d54c464ea18af6f69a Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sat, 3 Jun 2017 22:31:34 -0500 Subject: [PATCH 2/2] Toys: Add draw_annotation() and draw_point(). --- sumpy/toys.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sumpy/toys.py b/sumpy/toys.py index 562d570d..9262782a 100644 --- a/sumpy/toys.py +++ b/sumpy/toys.py @@ -494,6 +494,11 @@ def draw_circle(center, radius, **kwargs): plt.gca().add_patch(plt.Circle((center[0], center[1]), radius, **kwargs)) +def draw_point(loc, **kwargs): + import matplotlib.pyplot as plt + plt.plot(*loc, marker="o", **kwargs) + + def draw_arrow(from_pt, to_pt, shorten=0, **kwargs): import matplotlib.pyplot as plt dist = to_pt - from_pt @@ -503,6 +508,15 @@ def draw_arrow(from_pt, to_pt, shorten=0, **kwargs): plt.arrow(from_pt[0], from_pt[1], dist[0], dist[1], **kwargs) +def draw_annotation(from_pt, to_pt, label, **kwargs): + import matplotlib.pyplot as plt + + plt.gca().annotate(label, xy=from_pt, xytext=to_pt, + arrowprops=dict( + facecolor="white", edgecolor="white", shrink=0.05, + width=1, headwidth=5), color="white", **kwargs) + + class SchematicVisitor(object): def __init__(self, default_expn_style="circle"): self.default_expn_style = default_expn_style @@ -512,7 +526,7 @@ class SchematicVisitor(object): def visit_pointsources(self, psource): import matplotlib.pyplot as plt - plt.plot(psource.points[0], psource.points[1], "o") + plt.plot(psource.points[0], psource.points[1], "o", label="source") def visit_sum(self, psource): for ps in psource.psources: -- GitLab