Untitled
unknown
plain_text
23 days ago
740 B
1
Indexable
Never
import numpy as np import matplotlib.pyplot as plt # Function to plot regular polygons def plot_polygon(n, r=1, ax=None): # Calculate the angles for the vertices theta = np.linspace(0, 2 * np.pi, n + 1) x = r * np.cos(theta) y = r * np.sin(theta) if ax is None: fig, ax = plt.subplots(figsize=(5,5)) ax.plot(x, y, 'bo-') ax.set_aspect('equal') ax.grid(True) ax.set_title(f'Regular Polygon with {n} sides') # Create subplots to plot polygons with 6, 8, and 10 sides fig, axes = plt.subplots(1, 3, figsize=(15, 5)) # Plot polygons with 6, 8, and 10 sides plot_polygon(6, ax=axes[0]) plot_polygon(8, ax=axes[1]) plot_polygon(10, ax=axes[2]) # Display the plot plt.tight_layout() plt.show()
Leave a Comment