-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime_pair_constellations.py
More file actions
60 lines (51 loc) · 1.7 KB
/
prime_pair_constellations.py
File metadata and controls
60 lines (51 loc) · 1.7 KB
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
60
# prime_pair_constellations.py
import plotly.graph_objects as go
from core.primes import generate_primes
def run_visualization(limit, primes_list=None):
"""
Visualizes the Goldbach Conjecture as an interactive heatmap constellations of
prime pairs using Plotly.
Hover over any point to see the prime pair and their even sum.
"""
print("Generating interactive Prime Pair Constellation...")
if primes_list is None:
primes_list = generate_primes(limit)
x_coords = []
y_coords = []
text_labels = []
# Iterate through all prime pairs (p1,p2)
for i in range(len(primes_list)):
p1 = primes_list[i]
for j in range(i, len(primes_list)):
p2 = primes_list[j]
even_sum = p1 + p2
x_coords.append(p1)
y_coords.append(p2)
text_labels.append(f'{p1} + {p2} = {even_sum}')
# Plotly scatter plot
fig = go.Figure(data=go.Scatter(
x=x_coords,
y=y_coords,
mode='markers',
marker=dict(
size=5,
color=[val for val in x_coords],
colorscale='Viridis',
showscale=True,
colorbar_title="Prime Number"
),
text=text_labels, # This is the text that appears on hover
hoverinfo='text'
))
# Update plot layout for a cleaner look
fig.update_layout(
title=f'Goldbach Prime Pair Constellations (up to {limit})',
xaxis_title='Prime Number p1',
yaxis_title='Prime Number p2',
width=800,
height=800,
plot_bgcolor='black'
)
# Show the plot ( in browser window)
fig.show()
print("Interactive Prime Pair Constellation Visualization complete.")