-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMandelBrot.py
186 lines (156 loc) · 4.95 KB
/
MandelBrot.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, State, Input
import plotly.graph_objs as go
import numpy as np
from numba import jit
from textwrap import dedent as d
styles = {
'pre': {
'border': 'thin lightgrey solid',
'overflowX': 'scroll'
}
}
app = dash.Dash()
app.config['suppress_callback_exceptions'] = True
#######################################################################################################################
@jit
def mandelbrot(c, maxiter, threshold=2):
z = c
for n in range(maxiter):
if abs(z) > threshold:
return n
z = z * z + c
return 0
@jit
def mandelbrot_set(xmin, xmax, ymin, ymax, maxiter=250, width=1500, height=1500):
r1 = np.linspace(xmin, xmax, width)
r2 = np.linspace(ymin, ymax, height)
n3 = np.empty((width, height))
for i in range(width):
for j in range(height):
n3[i, j] = mandelbrot(r1[i] + 1j*r2[j], maxiter)
return r1, r2, n3
#######################################################################################################################
x, y, z = mandelbrot_set(-2.0, 0.5, -1.25, 1.25)
trace = go.Heatmap(x=x,
y=y,
z=z.T)
data = [trace]
layout = go.Layout(
title='Mandelbrot Plot',
width=1250,
height=1250,
xaxis = dict(
),
yaxis = dict(
scaleanchor = "x",
),
)
fig = go.Figure(data=data, layout=layout)
################################################################################
app.layout = html.Div([
################################################################################
# Title
html.H2('Zoom Application',
style={
'position': 'relative',
'top': '0px',
'left': '10px',
'font-family': 'Dosis',
'display': 'inline',
'font-size': '4.0rem',
'color': '#4D637F'
}),
html.H2('for',
style={
'position': 'relative',
'top': '0px',
'left': '20px',
'font-family': 'Dosis',
'display': 'inline',
'font-size': '2.0rem',
'color': '#4D637F'
}),
html.H2('MandelBrot',
style={
'position': 'relative',
'top': '0px',
'left': '27px',
'font-family': 'Dosis',
'display': 'inline',
'font-size': '4.0rem',
'color': '#4D637F'
}),
################################################################################
html.Br(),
html.Div([
dcc.Graph(
id='graph',
figure=fig
),
dcc.Slider(
id='iterations',
min=0,
max=500,
marks={
0: {'label': '0'},
50: {'label': '50'},
100: {'label': '100'},
150: {'label': '150'},
200: {'label': '200'},
250: {'label': '250'},
300: {'label': '300'},
350: {'label': '350'},
400: {'label': '400'},
450: {'label': '450'},
500: {'label': '500'},
},
value=250,
),
# html.Div([
# dcc.Markdown(d("""
# **Zoom and Relayout Data**
#
# Click and drag on the graph to zoom or click on the zoom
# buttons in the graph's menu bar.
# Clicking on legend items will also fire
# this event.
# """)),
# html.Pre(id='relayout-data', style=styles['pre']),
# ], className='three columns')
#
# ])
])
])
@app.callback(
# Output('relayout-data', 'children'),
Output('graph', 'figure'),
[Input('iterations', 'value'),
Input('graph', 'relayoutData')])
def display_selected_data(iterations, relayoutData):
xmin = relayoutData['xaxis.range[0]']
xmax = relayoutData['xaxis.range[1]']
ymin = relayoutData['yaxis.range[0]']
ymax = relayoutData['yaxis.range[1]']
x, y, z = mandelbrot_set(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, maxiter=iterations)
trace = go.Heatmap(x=x,
y=y,
z=z.T)
data = [trace]
layout = go.Layout(
title='Mandelbrot Plot',
width=1250,
height=1250,
xaxis = dict(
),
yaxis = dict(
scaleanchor = "x",
),
)
fig = go.Figure(data=data, layout=layout)
return fig
################################################################################
if __name__ == '__main__':
app.run_server(debug=True)