draw2 method

En esta página

draw2 method#

Se compara el draw2 con el draw original.

import proximitygraphs as pg
config = {
            'point_generator': {
                'name': 'normal_dist',
                'params': {'n': 500, 'dims': 2}
            },
            'transformations': [
                {
                    'name': 'perturb',
                    'params': {'radius': 0.25}
                }
            ],
            'graph': {
                'type': 'ProximityGraph',
                'name': 'Beta_Skeleton',
                'params': {'beta': 1.5}
            }
        }

points, graph = pg.Experiment(config).run()
import time

start_time = time.time()
graph.draw(figsize=(6, 6), v_size=5, e_size=1, v_color='red', e_color='blue', title=True, details=True, fontsize=10)
end_time = time.time()

print(f"Execution time: {end_time - start_time} seconds")
Execution time: 2.331360340118408 seconds
../../_images/40a23e0d1b27475c209f91717d578e9b788b80d0e2200874777654d845dd6412.png
import time

start_time2 = time.time()
graph.draw2(figsize=(6, 6), v_size=5, e_size=1, v_color='red', e_color='blue', title=True, details=True, fontsize=10)
end_time2 = time.time()

print(f"Execution time: {end_time2 - start_time2} seconds")
Execution time: 0.0128326416015625 seconds
../../_images/9d3634632ba9f33fd3bad50867b146e8ae18d584f8beb63de4c671fa09ff9f5b.png
import matplotlib.pyplot as plt

# Calculate execution times
time_draw = end_time - start_time
time_draw2 = end_time2 - start_time2

# Print metrics
print(f"draw execution time: {time_draw:.4f} seconds")
print(f"draw2 execution time: {time_draw2:.4f} seconds")

speedup = time_draw / time_draw2
print(f"draw2 is {speedup:.2f} times faster than draw. Wow!")

# Create a bar plot to compare the execution times
methods = ['draw', 'draw2']
times = [time_draw, time_draw2]

plt.figure(figsize=(8, 5))
plt.bar(methods, times, color=['blue', 'green'])
plt.ylabel('Execution Time (seconds)')
plt.title('Comparison of Execution Times for draw and draw2')
plt.show()
draw execution time: 2.3314 seconds
draw2 execution time: 0.0128 seconds
draw2 is 181.67 times faster than draw. Wow!
../../_images/7e8b9491f6767fc48b1f632c086efc2a7bf2f59dcbcf049ad12e7d4be588cc0c.png

Customization#

vcolor = '#051650'
ecolor = '#0A2472'
graph.draw2(figsize=(6, 6), v_size=2, e_size=1, v_alpha=1, e_alpha=1, v_color=vcolor, e_color=ecolor, title=True, details=True, fontsize=10)
(<Figure size 600x600 with 1 Axes>,
 <Axes: title={'center': 'beta-Skeleton\nbeta=1.5, closed=False, type=lune'}>)
../../_images/4b097bbf969487ceae9a04b1bf1e76e365914352ba78354d09311fa9b5e8fe02.png
from proximitygraphs import SetPoints

uniform_sphere = SetPoints.uniform_sphere(n=200, dims = 2, seed=0)
from proximitygraphs import Alpha_Hull, Alpha_Shape

H = Alpha_Hull(uniform_sphere, alpha=-5, n_points_per_arc=50)
H.draw(title=True, details=True, figsize=(6,6), v_size=2, e_size=1, v_color=vcolor, e_color=ecolor, fontsize=10)
(<Figure size 600x600 with 1 Axes>,
 <Axes: title={'center': 'Alpha-Hull\nalpha=-5'}>)
../../_images/137f61fc9b1b18c37a92d47e53f74c7ed5f8dff11f48a76615e1ed833860c399.png
from proximitygraphs import DelaunayG


H = DelaunayG(uniform_sphere)
H.draw(title=True, details=True, figsize=(6,6), v_size=3, e_size=1, v_color=vcolor, e_color=ecolor, fontsize=10)
(<Figure size 600x600 with 1 Axes>,
 <Axes: title={'center': 'Delaunay Triangulation'}>)
../../_images/29d3ad92a96401110ca10fcc2d09db81dd79bd4242e3214037686c62f29542b9.png
from proximitygraphs import Beta_Skeleton

H = Beta_Skeleton(uniform_sphere)
H.draw(title=True, details=True, figsize=(6,6), v_size=3, e_size=1, v_color=vcolor, e_color=ecolor, fontsize=10)
(<Figure size 600x600 with 1 Axes>,
 <Axes: title={'center': 'beta-Skeleton\nbeta=1.5, closed=False, type=lune'}>)
../../_images/c1920bc7423d5bfe75a7502f2183362e61dd80a4559f441130e54b72949c8686.png