gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Please write me some python code that can do the following: generate a drawing of a…
- User
Please write me some python code that can do the following: generate a drawing of a circle of diameter=6 with an equilateral triangle inside of it. Please send me the full python code and nothing else, no explanations
- Assistantpython
import matplotlib.pyplot as plt import numpy as np # Circle parameters diameter = 6 radius = diameter / 2 # Create a figure and axis fig, ax = plt.subplots() # Draw the circle circle = plt.Circle((0, 0), radius, edgecolor='blue', facecolor='none', linewidth=2) ax.add_artist(circle) # Calculate triangle vertices angle = np.pi / 3 # 60 degrees in radians triangle_vertices = np.array([ [radius * np.cos(0), radius * np.sin(0)], [radius * np.cos(angle), radius * np.sin(angle)], [radius * np.cos(2 * angle), radius * np.sin(2 * angle)] ]) # Draw the triangle triangle = plt.Polygon(triangle_vertices, edgecolor='red', facecolor='none', linewidth=2) ax.add_artist(triangle) # Set limits and aspect ax.set_xlim(-radius-1, radius+1) ax.set_ylim(-radius-1, radius+1) ax.set_aspect('equal', adjustable='box') # Remove axes ax.axis('off') # Show the plot plt.show()