Friday, 21 February 2025

Circle Pattern Plot using Python

 


import numpy as np

import matplotlib.pyplot as plt

radius=1

num_points=50

theta=np.linspace(0,2*np.pi,num_points)

x=radius*np.cos(theta)

y=radius*np.sin(theta)

fig,ax=plt.subplots()

ax.scatter(x,y,color='b',s=50)

ax.set_xlim(-1.2,1.2)

ax.set_ylim(-1.2,1.2)

ax.set_aspect('equal')

ax.axis('off')

plt.title("Circle pattern plot")

plt.show()

#source code --> clcoding.com 


Code Explanation:

1. Importing Required Libraries
import numpy as np
import matplotlib.pyplot as plt
numpy is used to generate numerical data, such as evenly spaced angles for plotting points.
matplotlib.pyplot is used to create the visualization.

2. Defining Circle Parameters
radius = 1
num_points = 50  # Number of dots
theta = np.linspace(0, 2 * np.pi, num_points)  # Angles for the circle
radius = 1: The radius of the circle.
num_points = 50: The number of dots to be placed around the circle.
np.linspace(0, 2 * np.pi, num_points):
This creates num_points evenly spaced values from 0 to 2π.
2π radians correspond to a full circle (360°).

3. Computing Circle Coordinates
x = radius * np.cos(theta)
y = radius * np.sin(theta)
np.cos(theta): Computes the x-coordinates of the points along the circle.
np.sin(theta): Computes the y-coordinates of the points along the circle.
Multiplying by radius ensures the points are scaled correctly.

4. Creating the Plot
fig, ax = plt.subplots()
ax.scatter(x, y, color='b', s=50)  # Scatter plot for dots
fig, ax = plt.subplots(): Creates a figure (fig) and an axis (ax) to plot on.
ax.scatter(x, y, color='b', s=50):
Uses scatter() to plot individual dots at (x, y).
color='b': Dots are blue (b for blue).
s=50: Size of each dot.

5. Setting Limits and Aspect Ratio
ax.set_xlim(-1.2, 1.2)
ax.set_ylim(-1.2, 1.2)
ax.set_aspect('equal')
ax.axis('off')  # Hide axes
ax.set_xlim(-1.2, 1.2): Sets x-axis limits slightly beyond the circle's radius for better visibility.
ax.set_ylim(-1.2, 1.2): Sets y-axis limits similarly.
ax.set_aspect('equal'): Ensures the aspect ratio is equal so the circle does not appear distorted.
ax.axis('off'): Hides the axes for a cleaner look.

6. Displaying the Plot
plt.show()
Displays the generated dotted circle.

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (96) AI (38) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (188) C (77) C# (12) C++ (83) Course (67) Coursera (247) Cybersecurity (25) Data Analysis (1) Data Analytics (2) data management (11) Data Science (142) Data Strucures (8) Deep Learning (21) Django (16) Downloads (3) edx (2) Engineering (14) Euron (29) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (9) Google (34) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (76) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1004) Python Coding Challenge (450) Python Quiz (87) Python Tips (4) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses

Python Coding for Kids ( Free Demo for Everyone)