import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 100)
y_upper = 1 - abs(x)
y_lower = abs(x) - 1
fig, ax = plt.subplots(figsize=(6, 6))
ax.fill_between(x, y_upper, 1, color="royalblue", alpha=0.7)
ax.fill_between(x, y_lower, -1, color="tomato", alpha=0.7)
ax.set_xlim(-1.2, 1.2)
ax.set_ylim(-1.2, 1.2)
ax.set_xticks([])
ax.set_yticks([])
ax.set_frame_on(False)
ax.axhline(0, color="black", linewidth=1.2, linestyle="--")
plt.title("Hourglass Pattern Plot")
plt.show()
#source code --> clcoding.com
Code Explanation:
Import Necessary Libraries
import numpy as np
0 Comments:
Post a Comment