tAdded circle plotting function to polyplot and example - polygen - generative … | |
git clone git://src.adamsgaard.dk/polygen | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit dd2cc4f4940e8f0b39ff31dcc03693e80dfa22ba | |
parent 70cefaf0bd158f8736b267ce085d8057294b726e | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 13 Mar 2014 22:14:48 +0100 | |
Added circle plotting function to polyplot and example | |
Diffstat: | |
M octahedron.py | 13 +++++++++++++ | |
M polygen.py | 5 +++++ | |
2 files changed, 18 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/octahedron.py b/octahedron.py | |
t@@ -1,9 +1,22 @@ | |
#!/usr/bin/env python | |
import polygen | |
+import matplotlib.pyplot as plt | |
+# Generate regular polygon with eight corners (octahedron) | |
octahedron = polygen.regular_star_polygon(8) | |
+ | |
+# Create the polygon plotting object | |
p = polygen.polyplot() | |
+ | |
+# Pass the octahedron points to the plot object | |
p.set_points(octahedron.points) | |
+ | |
+# Plot octahedron, do not draw lines to opposite points. Use custom colors. | |
p.plot_all_to_all(line_width=4, line_color='#666666', | |
exceptions=[[0,4], [1,5], [2,6], [3,7]]) | |
+ | |
+# Place red dot in center | |
+p.plot_circle([0,0], 0.34, color='#993333') | |
+ | |
+# Save figure as file | |
p.save_plot(background_color='#333333', transparent_background=False) | |
diff --git a/polygen.py b/polygen.py | |
t@@ -20,6 +20,7 @@ class polyplot: | |
show_axes=False, exceptions=[]): | |
self.points = numpy.asarray(self.points) | |
self.fig = plt.figure(figsize=figure_size_inches, dpi=dpi) | |
+ self.ax = self.fig.add_subplot(1, 1, 1) | |
for i in range(self.points.shape[0]): | |
for j in range(self.points.shape[0]): | |
if (i != j and | |
t@@ -35,6 +36,10 @@ class polyplot: | |
if show_axes == False: | |
plt.axis('off') | |
+ def plot_circle(self, coord, radius, color='black'): | |
+ circ = plt.Circle(coord, radius=radius, color=color) | |
+ self.ax.add_patch(circ) | |
+ | |
def save_plot(self, image_name='all_to_all', image_format='png', | |
background_color='white', | |
transparent_background=False): |