Commit 7c46ed41 authored by Manuel Schrauth's avatar Manuel Schrauth
Browse files

more encapsulation

parent a6b774f7
...@@ -31,13 +31,13 @@ def quick_plot(tiling, c='b', show_label=False, fs=5, save_img=False, path="", d ...@@ -31,13 +31,13 @@ def quick_plot(tiling, c='b', show_label=False, fs=5, save_img=False, path="", d
plt.show() plt.show()
# simple plot function for hyperbolic tiling with colors
def plot_tiling(polygon_list, colors, symmetric_colors=False, plot_colorbar=False, xcrange=(-1,1), ycrange=(-1,1), **kwargs): # convert list of HyperPolygon objects to matplotlib PatchCollection
fig, ax = plt.subplots(figsize=(8,8), dpi=120) def poly2patch(polygons, colors=None, **kwargs):
patches = [] patches = []
# loop over polygons # loop over polygons
for poly in polygon_list: for poly in polygons:
# extract vertex coordinates # extract vertex coordinates
u = poly.verticesP u = poly.verticesP
# transform to matplotlib Polygon format # transform to matplotlib Polygon format
...@@ -46,10 +46,22 @@ def plot_tiling(polygon_list, colors, symmetric_colors=False, plot_colorbar=Fals ...@@ -46,10 +46,22 @@ def plot_tiling(polygon_list, colors, symmetric_colors=False, plot_colorbar=Fals
patches.append(polygon) patches.append(polygon)
# the polygon list has now become a PatchCollection # the polygon list has now become a PatchCollection
pgons = PatchCollection(patches, **kwargs) pgonpatches = PatchCollection(patches, **kwargs)
# add colors
if colors is not None:
pgonpatches.set_array(np.array(colors))
return pgonpatches
# simple plot function for hyperbolic tiling with colors
def plot_tiling(polygons, colors, symmetric_colors=False, plot_colorbar=False, xcrange=(-1,1), ycrange=(-1,1), **kwargs):
fig, ax = plt.subplots(figsize=(10,7), dpi=120)
# convert to matplotlib format
pgons = poly2patch(polygons, colors, **kwargs)
# set colors and draw patches # draw patches
pgons.set_array(np.array(colors))
ax.add_collection(pgons) ax.add_collection(pgons)
# symmetric colorbar # symmetric colorbar
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment