-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy7.py
More file actions
40 lines (31 loc) · 1.53 KB
/
numpy7.py
File metadata and controls
40 lines (31 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import matplotlib.pyplot as plt
def draw_hourglass():
# Create the figure and axis
fig, ax = plt.subplots(figsize=(6, 6))
# 1. Draw the black axes (Crosshair)
# Horizontal line from x=-2 to 2 at y=0
ax.plot([-2, 2], [0, 0], color='black', linewidth=2)
# Vertical line from y=-2 to 2 at x=0
ax.plot([0, 0], [-2, 2], color='black', linewidth=2)
# 2. Draw the Red Hourglass (Left side)
# Vertices for the top triangle: (-1.3, 1), (-0.7, 1), (-1, 0)
# Vertices for the bottom triangle: (-1.3, -1), (-0.7, -1), (-1, 0)
# We combine them into one path to draw the outline
red_x = [-1.3, -0.7, -1, -1.3, -0.7, -1]
red_y = [1, 1, 0, -1, -1, 0]
# Plotting specific segments to match the hourglass shape
ax.plot([-1.3, -0.7, -1, -1.3], [1, 1, 0, 1], color='#D35400', linewidth=2) # Top
ax.plot([-1.3, -0.7, -1, -1.3], [-1, -1, 0, -1], color='#D35400', linewidth=2) # Bottom
# 3. Draw the Green Hourglass (Right side)
# Mirroring the coordinates to the right side (x + 2 approx)
ax.plot([0.7, 1.3, 1, 0.7], [1, 1, 0, 1], color='#00FF00', linewidth=2) # Top
ax.plot([0.7, 1.3, 1, 0.7], [-1, -1, 0, -1], color='#00FF00', linewidth=2) # Bottom
# Formatting the plot
ax.set_xlim(-2.5, 2.5)
ax.set_ylim(-2.5, 2.5)
ax.set_aspect('equal') # Keep the proportions square
# Hide the default spines and ticks to match the clean look of the image
plt.axis('off')
plt.show()
if __name__ == "__main__":
draw_hourglass()