-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_test.py
59 lines (45 loc) · 1.24 KB
/
color_test.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
import matplotlib
matplotlib.use("TkAgg") # Use TkAgg backend
import matplotlib.pyplot as plt
from enum import Enum
# Define an Enum class for colors
class Color(Enum):
BLUE = "#1f77b4"
ORANGE = "#ff7f0e"
GREEN = "#2ca02c"
RED = "#d62728"
PURPLE = "#9467bd"
# Main function to plot a "Happy Birthday" graph
def main():
x = np.linspace(-10, 10, 1001)
s = np.sinc(x)
# Create a figure and axis with specified figure size
fig, ax = plt.subplots(figsize=(10, 6))
# Hide the axes
ax.axis("off")
# Add some decorative elements
for i, color in enumerate(Color, start=1):
# Adjust the line positions so they are visible in the plot
ax.plot(
[i * 5 - 10, i * 5 + 10],
[abs(i * 0.2), abs(i * 0.2)],
color=color.value,
linewidth=4,
)
# Set the title using text, ensure it is within the figure bounds
ax.text(
0.5,
0.75,
"Happy Birthday!",
fontsize=25,
color=Color.GREEN.value,
ha="center",
va="center",
transform=ax.transAxes,
)
ax.plot(x, s, "--b", linewidth=5)
# Display the plot
plt.show()
if __name__ == "__main__":
main()