반응형
Spiral Web using Matplotlib and NumPy
# Spiral Web using Matplotlib and NumPy
import numpy as np
import matplotlib.pyplot as plt
def draw_spiral_web():
# Parameters
num_lines = 50 # Number of radial lines
num_circles = 10 # Number of concentric circles
max_radius = 10 # Maximum radius of the spiral web
# Generate theta for radial lines (angle from 0 to 2*pi)
theta = np.linspace(0, 2 * np.pi, num_lines, endpoint=False)
# Generate radii for concentric circles
radii = np.linspace(0, max_radius, num_circles)
# Create a figure
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw={'projection': 'polar'})
ax.set_facecolor('black') # Set background color to black
ax.set_xticks([]) # Remove angular ticks
ax.set_yticks([]) # Remove radial ticks
# Draw radial lines
for t in theta:
ax.plot([t, t], [0, max_radius], color='cyan', linewidth=0.7)
# Draw concentric circles
for r in radii:
ax.plot(np.linspace(0, 2 * np.pi, 100), [r] * 100, color='cyan', linewidth=0.7)
# Add a spiral
spiral_theta = np.linspace(0, 4 * np.pi, 500) # 2 full rotations
spiral_r = np.linspace(0, max_radius, 500)
ax.plot(spiral_theta, spiral_r, color='yellow', linewidth=1)
# Set aspect ratio and display the plot
ax.set_ylim(0, max_radius)
plt.show()
# Call the function to draw the spiral web
if __name__ == "__main__":
draw_spiral_web()
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[python] 초를 입력 받으면 카운트다운 하는 간단한 타이머 (0) | 2024.12.02 |
---|---|
[python] pip install wifi-qrcode-generator (0) | 2024.11.27 |
[python] Sunburst Chart (0) | 2024.11.26 |
[python] What’s New in Python 3.13 (0) | 2024.11.19 |
[python] pyQt, requests, BeautifulSoup 이용한 웹크롤링 (1) | 2024.11.15 |