freealg 0.7.16__py3-none-any.whl → 0.7.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- freealg/__init__.py +8 -6
- freealg/__version__.py +1 -1
- freealg/_algebraic_form/_branch_points.py +18 -18
- freealg/_algebraic_form/_continuation_algebraic.py +13 -13
- freealg/_algebraic_form/_cusp.py +15 -15
- freealg/_algebraic_form/_cusp_wrap.py +6 -6
- freealg/_algebraic_form/_decompress.py +16 -16
- freealg/_algebraic_form/_decompress4.py +31 -31
- freealg/_algebraic_form/_decompress5.py +23 -23
- freealg/_algebraic_form/_decompress6.py +13 -13
- freealg/_algebraic_form/_decompress7.py +15 -15
- freealg/_algebraic_form/_decompress8.py +17 -17
- freealg/_algebraic_form/_decompress9.py +18 -18
- freealg/_algebraic_form/_decompress_new.py +17 -17
- freealg/_algebraic_form/_decompress_new_2.py +57 -57
- freealg/_algebraic_form/_decompress_util.py +10 -10
- freealg/_algebraic_form/_decompressible.py +292 -0
- freealg/_algebraic_form/_edge.py +10 -10
- freealg/_algebraic_form/_homotopy4.py +9 -9
- freealg/_algebraic_form/_homotopy5.py +9 -9
- freealg/_algebraic_form/_support.py +19 -19
- freealg/_algebraic_form/algebraic_form.py +262 -468
- freealg/_base_form.py +401 -0
- freealg/_free_form/__init__.py +1 -4
- freealg/_free_form/_density_util.py +1 -1
- freealg/_free_form/_plot_util.py +3 -511
- freealg/_free_form/free_form.py +8 -367
- freealg/_util.py +59 -11
- freealg/distributions/__init__.py +2 -1
- freealg/distributions/_base_distribution.py +163 -0
- freealg/distributions/_chiral_block.py +137 -11
- freealg/distributions/_compound_poisson.py +168 -64
- freealg/distributions/_deformed_marchenko_pastur.py +137 -88
- freealg/distributions/_deformed_wigner.py +92 -40
- freealg/distributions/_fuss_catalan.py +269 -0
- freealg/distributions/_kesten_mckay.py +4 -130
- freealg/distributions/_marchenko_pastur.py +8 -196
- freealg/distributions/_meixner.py +4 -130
- freealg/distributions/_wachter.py +4 -130
- freealg/distributions/_wigner.py +10 -127
- freealg/visualization/__init__.py +2 -2
- freealg/visualization/{_rgb_hsv.py → _domain_coloring.py} +37 -29
- freealg/visualization/_plot_util.py +513 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/METADATA +1 -1
- freealg-0.7.18.dist-info/RECORD +74 -0
- freealg-0.7.16.dist-info/RECORD +0 -69
- /freealg/{_free_form/_sample.py → _sample.py} +0 -0
- /freealg/{_free_form/_support.py → _support.py} +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/WHEEL +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/licenses/AUTHORS.txt +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/licenses/LICENSE.txt +0 -0
- {freealg-0.7.16.dist-info → freealg-0.7.18.dist-info}/top_level.txt +0 -0
freealg/_free_form/_plot_util.py
CHANGED
|
@@ -14,13 +14,8 @@
|
|
|
14
14
|
import numpy
|
|
15
15
|
import matplotlib.pyplot as plt
|
|
16
16
|
import texplot
|
|
17
|
-
import matplotlib
|
|
18
|
-
import colorsys
|
|
19
|
-
import matplotlib.ticker as ticker
|
|
20
|
-
import matplotlib.gridspec as gridspec
|
|
21
17
|
|
|
22
|
-
__all__ = ['plot_fit'
|
|
23
|
-
'plot_stieltjes_on_disk', 'plot_samples']
|
|
18
|
+
__all__ = ['plot_fit']
|
|
24
19
|
|
|
25
20
|
|
|
26
21
|
# ========
|
|
@@ -30,6 +25,8 @@ __all__ = ['plot_fit', 'plot_density', 'plot_hilbert', 'plot_stieltjes',
|
|
|
30
25
|
def plot_fit(psi, x_supp, g_supp, g_supp_approx, support, latex=False,
|
|
31
26
|
save=False):
|
|
32
27
|
"""
|
|
28
|
+
Plot fitted psi coefficients. This is a helper for
|
|
29
|
+
:func:`FreeForm.fit` when ``plot=True``.
|
|
33
30
|
"""
|
|
34
31
|
|
|
35
32
|
with texplot.theme(use_latex=latex):
|
|
@@ -91,508 +88,3 @@ def plot_fit(psi, x_supp, g_supp, g_supp_approx, support, latex=False,
|
|
|
91
88
|
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
92
89
|
transparent_background=True, dpi=400,
|
|
93
90
|
show_and_save=save_status, verbose=True)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# =========
|
|
97
|
-
# auto bins
|
|
98
|
-
# =========
|
|
99
|
-
|
|
100
|
-
def _auto_bins(array, method='scott', factor=5):
|
|
101
|
-
"""
|
|
102
|
-
Automatic choice for the number of bins for the histogram of an array.
|
|
103
|
-
|
|
104
|
-
Parameters
|
|
105
|
-
----------
|
|
106
|
-
|
|
107
|
-
array : numpy.array
|
|
108
|
-
An array for histogram.
|
|
109
|
-
|
|
110
|
-
method : {``'freedman'``, ``'scott'``, ``'sturges'``}, default= ``'scott'``
|
|
111
|
-
Method of choosing number of bins.
|
|
112
|
-
|
|
113
|
-
Returns
|
|
114
|
-
-------
|
|
115
|
-
|
|
116
|
-
num_bins : int
|
|
117
|
-
Number of bins for histogram.
|
|
118
|
-
"""
|
|
119
|
-
|
|
120
|
-
if method == 'freedman':
|
|
121
|
-
|
|
122
|
-
q75, q25 = numpy.percentile(array, [75, 25])
|
|
123
|
-
iqr = q75 - q25
|
|
124
|
-
bin_width = 2 * iqr / (len(array) ** (1/3))
|
|
125
|
-
|
|
126
|
-
if bin_width == 0:
|
|
127
|
-
# Fallback default
|
|
128
|
-
return
|
|
129
|
-
num_bins = 100
|
|
130
|
-
else:
|
|
131
|
-
num_bins = int(numpy.ceil((array.max() - array.min()) / bin_width))
|
|
132
|
-
|
|
133
|
-
elif method == 'scott':
|
|
134
|
-
|
|
135
|
-
std = numpy.std(array)
|
|
136
|
-
bin_width = 3.5 * std / (len(array) ** (1/3))
|
|
137
|
-
num_bins = int(numpy.ceil((array.max() - array.min()) / bin_width))
|
|
138
|
-
|
|
139
|
-
elif method == 'sturges':
|
|
140
|
-
|
|
141
|
-
num_bins = int(numpy.ceil(numpy.log2(len(array)) + 1))
|
|
142
|
-
|
|
143
|
-
else:
|
|
144
|
-
raise NotImplementedError('"method" is invalid.')
|
|
145
|
-
|
|
146
|
-
return num_bins * factor
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
# ============
|
|
150
|
-
# plot density
|
|
151
|
-
# ============
|
|
152
|
-
|
|
153
|
-
def plot_density(x, rho, eig=None, support=None, label='',
|
|
154
|
-
title='Spectral Density', latex=False, save=False):
|
|
155
|
-
"""
|
|
156
|
-
"""
|
|
157
|
-
|
|
158
|
-
with texplot.theme(use_latex=latex):
|
|
159
|
-
|
|
160
|
-
fig, ax = plt.subplots(figsize=(6, 2.7))
|
|
161
|
-
|
|
162
|
-
if eig is not None:
|
|
163
|
-
if support is not None:
|
|
164
|
-
lam_m, lam_p = support
|
|
165
|
-
else:
|
|
166
|
-
lam_m, lam_p = min(eig), max(eig)
|
|
167
|
-
bins = numpy.linspace(lam_m, lam_p, _auto_bins(eig))
|
|
168
|
-
_ = ax.hist(eig, bins, density=True, color='silver',
|
|
169
|
-
edgecolor='none', label='Histogram')
|
|
170
|
-
else:
|
|
171
|
-
plt.fill_between(x, y1=rho, y2=0, color='silver', zorder=-1)
|
|
172
|
-
|
|
173
|
-
ax.plot(x, rho, color='black', label=label, zorder=3)
|
|
174
|
-
ax.set_xlabel(r'$\lambda$')
|
|
175
|
-
ax.set_ylabel(r'$\rho(\lambda)$''')
|
|
176
|
-
ax.set_xlim([x[0], x[-1]])
|
|
177
|
-
ax.set_ylim(bottom=0)
|
|
178
|
-
ax.set_title(title)
|
|
179
|
-
|
|
180
|
-
if label != '':
|
|
181
|
-
ax.legend(fontsize='small')
|
|
182
|
-
|
|
183
|
-
# Save
|
|
184
|
-
if save is False:
|
|
185
|
-
save_status = False
|
|
186
|
-
save_filename = ''
|
|
187
|
-
else:
|
|
188
|
-
save_status = True
|
|
189
|
-
if isinstance(save, str):
|
|
190
|
-
save_filename = save
|
|
191
|
-
else:
|
|
192
|
-
save_filename = 'density.pdf'
|
|
193
|
-
|
|
194
|
-
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
195
|
-
transparent_background=True, dpi=400,
|
|
196
|
-
show_and_save=save_status, verbose=True)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# ============
|
|
200
|
-
# plot hilbert
|
|
201
|
-
# ============
|
|
202
|
-
|
|
203
|
-
def plot_hilbert(x, hilb, support=None, latex=False, save=False):
|
|
204
|
-
"""
|
|
205
|
-
"""
|
|
206
|
-
|
|
207
|
-
with texplot.theme(use_latex=latex):
|
|
208
|
-
|
|
209
|
-
fig, ax = plt.subplots(figsize=(6, 2.7))
|
|
210
|
-
|
|
211
|
-
if support is not None:
|
|
212
|
-
lam_m, lam_p = support
|
|
213
|
-
ax.plot(x, hilb, color='black', zorder=3)
|
|
214
|
-
ax.axvline(lam_m, linestyle='--', linewidth=1, color='darkgray',
|
|
215
|
-
label=r'$\lambda_{\pm}$')
|
|
216
|
-
ax.axvline(lam_p, linestyle='--', linewidth=1, color='darkgray')
|
|
217
|
-
|
|
218
|
-
ax.axhline(0, linestyle='--', linewidth=0.5, color='gray', zorder=-1)
|
|
219
|
-
|
|
220
|
-
ax.set_xlim([x[0], x[-1]])
|
|
221
|
-
ax.set_xlabel(r'$x$')
|
|
222
|
-
ax.set_ylabel(r'$\mathcal{H}[\rho](x)$')
|
|
223
|
-
ax.set_title('Hilbert Transform')
|
|
224
|
-
ax.legend(fontsize='small')
|
|
225
|
-
|
|
226
|
-
# Make sure y=0 is in the y ticks.
|
|
227
|
-
yt = list(ax.get_yticks())
|
|
228
|
-
if 0 not in yt:
|
|
229
|
-
yt.append(0)
|
|
230
|
-
yt = sorted(yt)
|
|
231
|
-
ax.set_yticks(yt)
|
|
232
|
-
|
|
233
|
-
# Save
|
|
234
|
-
if save is False:
|
|
235
|
-
save_status = False
|
|
236
|
-
save_filename = ''
|
|
237
|
-
else:
|
|
238
|
-
save_status = True
|
|
239
|
-
if isinstance(save, str):
|
|
240
|
-
save_filename = save
|
|
241
|
-
else:
|
|
242
|
-
save_filename = 'hilbert.pdf'
|
|
243
|
-
|
|
244
|
-
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
245
|
-
transparent_background=True, dpi=400,
|
|
246
|
-
show_and_save=save_status, verbose=True)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
# =======
|
|
250
|
-
# rgb hsv
|
|
251
|
-
# =======
|
|
252
|
-
|
|
253
|
-
def _rgb_hsv(c, shift=0.0, thresh=numpy.inf):
|
|
254
|
-
"""
|
|
255
|
-
Convert complex field c to rgb through hsv channel.
|
|
256
|
-
"""
|
|
257
|
-
|
|
258
|
-
hue = (numpy.angle(c) + numpy.pi) / (2.0 * numpy.pi)
|
|
259
|
-
hue = (hue + shift) % 1.0
|
|
260
|
-
saturation = numpy.ones_like(hue)
|
|
261
|
-
|
|
262
|
-
# max_val = numpy.max(numpy.abs(c))
|
|
263
|
-
# max_val = numpy.min([thresh, max_val])
|
|
264
|
-
# value = numpy.abs(c) / max_val
|
|
265
|
-
# value = numpy.where(value > 1, V, value)
|
|
266
|
-
value = 1.0 - numpy.exp(-numpy.abs(c))
|
|
267
|
-
|
|
268
|
-
hsv = numpy.stack((hue, saturation, value), axis=-1)
|
|
269
|
-
rgb = matplotlib.colors.hsv_to_rgb(hsv)
|
|
270
|
-
|
|
271
|
-
return rgb
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
# =======
|
|
275
|
-
# rgb hsl
|
|
276
|
-
# =======
|
|
277
|
-
|
|
278
|
-
def _rgb_hsl(c, shift=0.0):
|
|
279
|
-
"""
|
|
280
|
-
Convert complex field to rgb though hsl channel.
|
|
281
|
-
"""
|
|
282
|
-
|
|
283
|
-
# Use constant lightness to avoid everything becoming white.
|
|
284
|
-
hue = (numpy.angle(c) + numpy.pi) / (2.0 * numpy.pi)
|
|
285
|
-
hue = (hue + shift) % 1.0
|
|
286
|
-
lightness = 0.5 * numpy.ones_like(hue)
|
|
287
|
-
saturation = numpy.ones_like(hue)
|
|
288
|
-
f = numpy.vectorize(lambda h_, l_, s_: colorsys.hls_to_rgb(h_, l_, s_))
|
|
289
|
-
r, g, b = f(hue, lightness, saturation)
|
|
290
|
-
rgb = numpy.stack((r, g, b), axis=-1)
|
|
291
|
-
|
|
292
|
-
return rgb
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
# ===============
|
|
296
|
-
# value formatter
|
|
297
|
-
# ===============
|
|
298
|
-
|
|
299
|
-
def _value_formatter(v, pos):
|
|
300
|
-
"""
|
|
301
|
-
"""
|
|
302
|
-
|
|
303
|
-
# v is the normalized "value" channel: v = 1 - exp(-|m(z)|)
|
|
304
|
-
# Invert the mapping: |m(z)| = -ln(1-v)
|
|
305
|
-
if v >= 1:
|
|
306
|
-
return r'$\infty$'
|
|
307
|
-
elif v == 0:
|
|
308
|
-
return r'0'
|
|
309
|
-
else:
|
|
310
|
-
m_val = -numpy.log(1 - v)
|
|
311
|
-
return f"{m_val:.1f}"
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
# ==============
|
|
315
|
-
# plot stieltjes
|
|
316
|
-
# ==============
|
|
317
|
-
|
|
318
|
-
def plot_stieltjes(x, y, m1, m2, support, latex=False, save=False):
|
|
319
|
-
"""
|
|
320
|
-
"""
|
|
321
|
-
|
|
322
|
-
lam_m, lam_p = support
|
|
323
|
-
x_min = numpy.min(x)
|
|
324
|
-
x_max = numpy.max(x)
|
|
325
|
-
y_min = numpy.min(y)
|
|
326
|
-
y_max = numpy.max(y)
|
|
327
|
-
n_y = y.size
|
|
328
|
-
|
|
329
|
-
with texplot.theme(use_latex=latex):
|
|
330
|
-
|
|
331
|
-
fig = plt.figure(figsize=(12, 4))
|
|
332
|
-
gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 0.2], wspace=0.3)
|
|
333
|
-
|
|
334
|
-
eps = 2 / n_y
|
|
335
|
-
shift = 0.0
|
|
336
|
-
|
|
337
|
-
ax0 = fig.add_subplot(gs[0])
|
|
338
|
-
ax0.imshow(_rgb_hsv(m1, shift=shift),
|
|
339
|
-
extent=[x_min, x_max, y_min, y_max], origin='lower',
|
|
340
|
-
interpolation='gaussian', rasterized=True)
|
|
341
|
-
ax0.plot([lam_m, lam_p], [eps, eps], 'o', markersize=1.5,
|
|
342
|
-
color='black')
|
|
343
|
-
ax0.plot([lam_m, lam_p], [eps, eps], '-', linewidth=1, color='black')
|
|
344
|
-
ax0.set_xlabel(r'$\mathrm{Re}(z)$')
|
|
345
|
-
ax0.set_ylabel(r'$\mathrm{Im}(z)$')
|
|
346
|
-
ax0.set_title(r'(a) Principal Branch on $\mathbb{C}^{+}$ and ' +
|
|
347
|
-
r'$\mathbb{C}^{-}$')
|
|
348
|
-
ax0.set_yticks(numpy.arange(y_min, y_max+0.01, 0.5))
|
|
349
|
-
ax0.set_xlim([x_min, x_max])
|
|
350
|
-
ax0.set_ylim([y_min, y_max])
|
|
351
|
-
|
|
352
|
-
ax1 = fig.add_subplot(gs[1])
|
|
353
|
-
ax1.imshow(_rgb_hsv(m2, shift=shift),
|
|
354
|
-
extent=[x_min, x_max, y_min, y_max], origin='lower',
|
|
355
|
-
interpolation='gaussian', rasterized=True)
|
|
356
|
-
ax1.plot([lam_m, lam_p], [eps, eps], 'o', markersize=1.5,
|
|
357
|
-
color='black')
|
|
358
|
-
ax1.plot([x_min, lam_m], [eps, eps], '-', linewidth=1, color='black')
|
|
359
|
-
ax1.plot([lam_p, x_max], [eps, eps], '-', linewidth=1, color='black')
|
|
360
|
-
ax1.set_xlabel(r'$\mathrm{Re}(z)$')
|
|
361
|
-
ax1.set_ylabel(r'$\mathrm{Im}(z)$')
|
|
362
|
-
ax1.set_title(r'(b) Principal Branch on $\mathbb{C}^{+}$, Secondary ' +
|
|
363
|
-
r'Branch on $\mathbb{C}^{-}$')
|
|
364
|
-
ax1.set_yticks(numpy.arange(y_min, y_max+0.01, 0.5))
|
|
365
|
-
ax1.set_xlim([x_min, x_max])
|
|
366
|
-
ax1.set_ylim([y_min, y_max])
|
|
367
|
-
|
|
368
|
-
pos = ax1.get_position()
|
|
369
|
-
cbar_width = 0.013
|
|
370
|
-
pad = 0.013
|
|
371
|
-
|
|
372
|
-
# gs_cb = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=gs[2],
|
|
373
|
-
# hspace=0.4)
|
|
374
|
-
gridspec.GridSpecFromSubplotSpec(1, 2, subplot_spec=gs[2],
|
|
375
|
-
width_ratios=[1, 1], wspace=0.05)
|
|
376
|
-
|
|
377
|
-
# Create two separate axes for colorbars using make_axes_locatable:
|
|
378
|
-
# divider = make_axes_locatable(ax[1])
|
|
379
|
-
# cax_hue = divider.append_axes("right", size="4%", pad=0.12)
|
|
380
|
-
# cax_value = divider.append_axes("right", size="4%", pad=0.7)
|
|
381
|
-
|
|
382
|
-
# cax_hue = fig.add_subplot(gs_cb[0])
|
|
383
|
-
cax_hue = fig.add_axes([pos.x1 + pad, pos.y0, cbar_width, pos.height])
|
|
384
|
-
norm_hue = matplotlib.colors.Normalize(vmin=-numpy.pi, vmax=numpy.pi)
|
|
385
|
-
cmap_hue = plt.get_cmap('hsv')
|
|
386
|
-
sm_hue = plt.cm.ScalarMappable(norm=norm_hue, cmap=cmap_hue)
|
|
387
|
-
sm_hue.set_array([])
|
|
388
|
-
cb_hue = fig.colorbar(sm_hue, cax=cax_hue)
|
|
389
|
-
cb_hue.set_label(r'$\mathrm{Arg}(m(z))$', labelpad=-6)
|
|
390
|
-
cb_hue.set_ticks([-numpy.pi, 0, numpy.pi])
|
|
391
|
-
cb_hue.set_ticklabels([r'$-\pi$', '0', r'$\pi$'])
|
|
392
|
-
|
|
393
|
-
# cax_value = fig.add_subplot(gs_cb[1])
|
|
394
|
-
cax_value = fig.add_axes([pos.x1 + 4.4*pad + cbar_width, pos.y0,
|
|
395
|
-
cbar_width, pos.height])
|
|
396
|
-
norm_value = matplotlib.colors.Normalize(vmin=0, vmax=1)
|
|
397
|
-
cmap_value = plt.get_cmap('gray')
|
|
398
|
-
sm_value = plt.cm.ScalarMappable(norm=norm_value, cmap=cmap_value)
|
|
399
|
-
sm_value.set_array([])
|
|
400
|
-
cb_value = fig.colorbar(sm_value, cax=cax_value)
|
|
401
|
-
ticks_norm = [0, 1 - numpy.exp(-0.5), 1 - numpy.exp(-1),
|
|
402
|
-
1 - numpy.exp(-2), 1]
|
|
403
|
-
cb_value.set_ticks(ticks_norm)
|
|
404
|
-
cb_value.ax.yaxis.set_major_formatter(
|
|
405
|
-
ticker.FuncFormatter(_value_formatter))
|
|
406
|
-
cb_value.set_ticklabels(["0", r"$\frac{1}{2}$", "1", "2", r"$\infty$"])
|
|
407
|
-
cb_value.set_label(r'$|m(z)|$', labelpad=0)
|
|
408
|
-
|
|
409
|
-
plt.tight_layout()
|
|
410
|
-
|
|
411
|
-
# Save
|
|
412
|
-
if save is False:
|
|
413
|
-
save_status = False
|
|
414
|
-
save_filename = ''
|
|
415
|
-
else:
|
|
416
|
-
save_status = True
|
|
417
|
-
if isinstance(save, str):
|
|
418
|
-
save_filename = save
|
|
419
|
-
else:
|
|
420
|
-
save_filename = 'stieltjes.pdf'
|
|
421
|
-
|
|
422
|
-
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
423
|
-
transparent_background=True, dpi=400,
|
|
424
|
-
show_and_save=save_status, verbose=True)
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
# ======================
|
|
428
|
-
# plot stieltjes on disk
|
|
429
|
-
# ======================
|
|
430
|
-
|
|
431
|
-
def plot_stieltjes_on_disk(r, t, m1_D, m2_D, support, latex=False, save=False):
|
|
432
|
-
"""
|
|
433
|
-
"""
|
|
434
|
-
|
|
435
|
-
grid_r, grid_t = numpy.meshgrid(r, t)
|
|
436
|
-
|
|
437
|
-
# Inverse Cayley
|
|
438
|
-
lam_m, lam_p = support
|
|
439
|
-
lam_p_z = (lam_p - 1j) / (lam_p + 1j)
|
|
440
|
-
lam_m_z = (lam_m - 1j) / (lam_m + 1j)
|
|
441
|
-
theta_p = numpy.angle(lam_p_z)
|
|
442
|
-
theta_n = numpy.angle(lam_m_z)
|
|
443
|
-
|
|
444
|
-
if theta_n < 0:
|
|
445
|
-
theta_n += 2.0 * numpy.pi
|
|
446
|
-
if theta_p < 0:
|
|
447
|
-
theta_p += 2.0 * numpy.pi
|
|
448
|
-
|
|
449
|
-
theta_branch = numpy.linspace(theta_n, theta_p, 100)
|
|
450
|
-
theta_alt_branch = numpy.linspace(theta_p, theta_n + 2*numpy.pi, 100)
|
|
451
|
-
r_branch = numpy.ones_like(theta_branch)
|
|
452
|
-
|
|
453
|
-
with texplot.theme(use_latex=latex):
|
|
454
|
-
|
|
455
|
-
fig = plt.figure(figsize=(12, 4))
|
|
456
|
-
# gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 0.2], wspace=0.3)
|
|
457
|
-
gs = gridspec.GridSpec(1, 3, width_ratios=[1, 1, 0.2], wspace=-0.75)
|
|
458
|
-
|
|
459
|
-
shift = 0.0
|
|
460
|
-
|
|
461
|
-
ax0 = fig.add_subplot(gs[0], projection='polar')
|
|
462
|
-
ax0.pcolormesh(grid_t, grid_r, _rgb_hsv(m1_D, shift=shift),
|
|
463
|
-
shading='auto', rasterized=True)
|
|
464
|
-
ax0.plot(theta_branch, r_branch, '-', linewidth=1, color='black')
|
|
465
|
-
ax0.plot(theta_n, 0.994, 'o', markersize=1.5, color='black')
|
|
466
|
-
ax0.plot(theta_p, 0.994, 'o', markersize=1.5, color='black')
|
|
467
|
-
ax0.set_theta_zero_location("E") # zero on left
|
|
468
|
-
ax0.set_theta_direction(1) # angles increase anti-clockwise
|
|
469
|
-
# ax.set_rticks([1, r_max])
|
|
470
|
-
ax0.set_rticks([])
|
|
471
|
-
ax0.set_thetagrids(
|
|
472
|
-
angles=[0, 90, 180, 270],
|
|
473
|
-
labels=[r'$0$', r'$\frac{\pi}{2}$', r'$\pi$', r'$\frac{3\pi}{2}$'])
|
|
474
|
-
ax0.tick_params(axis='x', pad=-2)
|
|
475
|
-
ax0.grid(False)
|
|
476
|
-
# ax0.set_xlabel(r'$\mathrm{Re}(z)$')
|
|
477
|
-
# ax0.set_ylabel(r'$\mathrm{Im}(z)$')
|
|
478
|
-
ax0.set_title(
|
|
479
|
-
r'(a) Principal Branch on $\mathbb{D}$ and $\mathbb{D}^{c}$',
|
|
480
|
-
pad=25)
|
|
481
|
-
|
|
482
|
-
ax1 = fig.add_subplot(gs[1], projection='polar')
|
|
483
|
-
ax1.pcolormesh(grid_t, grid_r, _rgb_hsv(m2_D, shift=shift),
|
|
484
|
-
shading='auto', rasterized=True)
|
|
485
|
-
ax1.plot(theta_alt_branch, r_branch, '-', linewidth=1, color='black')
|
|
486
|
-
ax1.plot(theta_n, 0.994, 'o', markersize=1.5, color='black')
|
|
487
|
-
ax1.plot(theta_p, 0.994, 'o', markersize=1.5, color='black')
|
|
488
|
-
ax1.set_theta_zero_location("E") # zero on left
|
|
489
|
-
ax1.set_theta_direction(1) # angles increase anti-clockwise
|
|
490
|
-
# ax.set_rticks([1, r_max])
|
|
491
|
-
ax1.set_rticks([])
|
|
492
|
-
ax1.set_thetagrids(
|
|
493
|
-
angles=[0, 90, 180, 270],
|
|
494
|
-
labels=[r'$0$', r'$\frac{\pi}{2}$', r'$\pi$', r'$\frac{3\pi}{2}$'])
|
|
495
|
-
ax1.tick_params(axis='x', pad=-2)
|
|
496
|
-
ax1.grid(False)
|
|
497
|
-
# ax0.set_xlabel(r'$\mathrm{Re}(z)$')
|
|
498
|
-
# ax0.set_ylabel(r'$\mathrm{Im}(z)$')
|
|
499
|
-
ax1.set_title(r'(b) Principal Branch on $\mathbb{D}$, Secondary ' +
|
|
500
|
-
r'Branch on $\mathbb{D}^{c}$', pad=25)
|
|
501
|
-
|
|
502
|
-
pos = ax1.get_position()
|
|
503
|
-
cbar_width = 0.013
|
|
504
|
-
pad = 0.013
|
|
505
|
-
|
|
506
|
-
# gs_cb = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=gs[2],
|
|
507
|
-
# hspace=0.4)
|
|
508
|
-
gridspec.GridSpecFromSubplotSpec(1, 2, subplot_spec=gs[2],
|
|
509
|
-
width_ratios=[1, 1], wspace=0.08)
|
|
510
|
-
|
|
511
|
-
# Create two separate axes for colorbars using make_axes_locatable:
|
|
512
|
-
# divider = make_axes_locatable(ax[1])
|
|
513
|
-
# cax_hue = divider.append_axes("right", size="4%", pad=0.12)
|
|
514
|
-
# cax_value = divider.append_axes("right", size="4%", pad=0.7)
|
|
515
|
-
|
|
516
|
-
# cax_hue = fig.add_subplot(gs_cb[0])
|
|
517
|
-
cax_hue = fig.add_axes(
|
|
518
|
-
[pos.x1 + 2.5*pad, pos.y0, cbar_width, pos.height])
|
|
519
|
-
norm_hue = matplotlib.colors.Normalize(vmin=-numpy.pi, vmax=numpy.pi)
|
|
520
|
-
cmap_hue = plt.get_cmap('hsv')
|
|
521
|
-
sm_hue = plt.cm.ScalarMappable(norm=norm_hue, cmap=cmap_hue)
|
|
522
|
-
sm_hue.set_array([])
|
|
523
|
-
cb_hue = fig.colorbar(sm_hue, cax=cax_hue)
|
|
524
|
-
cb_hue.set_label(r'$\mathrm{Arg}(m(\zeta))$', labelpad=-6)
|
|
525
|
-
cb_hue.set_ticks([-numpy.pi, 0, numpy.pi])
|
|
526
|
-
cb_hue.set_ticklabels([r'$-\pi$', '0', r'$\pi$'])
|
|
527
|
-
|
|
528
|
-
# cax_value = fig.add_subplot(gs_cb[1])
|
|
529
|
-
cax_value = fig.add_axes([pos.x1 + (4.4+2.5)*pad + cbar_width, pos.y0,
|
|
530
|
-
cbar_width, pos.height])
|
|
531
|
-
norm_value = matplotlib.colors.Normalize(vmin=0, vmax=1)
|
|
532
|
-
cmap_value = plt.get_cmap('gray')
|
|
533
|
-
sm_value = plt.cm.ScalarMappable(norm=norm_value, cmap=cmap_value)
|
|
534
|
-
sm_value.set_array([])
|
|
535
|
-
cb_value = fig.colorbar(sm_value, cax=cax_value)
|
|
536
|
-
ticks_norm = [0, 1 - numpy.exp(-0.5), 1 - numpy.exp(-1),
|
|
537
|
-
1 - numpy.exp(-2), 1]
|
|
538
|
-
cb_value.set_ticks(ticks_norm)
|
|
539
|
-
cb_value.ax.yaxis.set_major_formatter(ticker.FuncFormatter(
|
|
540
|
-
_value_formatter))
|
|
541
|
-
cb_value.set_ticklabels(["0", r"$\frac{1}{2}$", "1", "2", r"$\infty$"])
|
|
542
|
-
cb_value.set_label(r'$|m(\zeta)|$', labelpad=0)
|
|
543
|
-
|
|
544
|
-
plt.tight_layout()
|
|
545
|
-
|
|
546
|
-
# Save
|
|
547
|
-
if save is False:
|
|
548
|
-
save_status = False
|
|
549
|
-
save_filename = ''
|
|
550
|
-
else:
|
|
551
|
-
save_status = True
|
|
552
|
-
if isinstance(save, str):
|
|
553
|
-
save_filename = save
|
|
554
|
-
else:
|
|
555
|
-
save_filename = 'stieltjes_disk.pdf'
|
|
556
|
-
|
|
557
|
-
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
558
|
-
transparent_background=True, dpi=400,
|
|
559
|
-
show_and_save=save_status, verbose=True)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
# ============
|
|
563
|
-
# plot samples
|
|
564
|
-
# ============
|
|
565
|
-
|
|
566
|
-
def plot_samples(x, rho, x_min, x_max, samples, latex=False, save=False):
|
|
567
|
-
"""
|
|
568
|
-
"""
|
|
569
|
-
|
|
570
|
-
with texplot.theme(use_latex=latex):
|
|
571
|
-
|
|
572
|
-
fig, ax = plt.subplots(figsize=(6, 3))
|
|
573
|
-
|
|
574
|
-
bins = numpy.linspace(x_min, x_max, _auto_bins(samples))
|
|
575
|
-
_ = ax.hist(samples, bins, density=True, color='silver',
|
|
576
|
-
edgecolor='none', label='Samples histogram')
|
|
577
|
-
ax.plot(x, rho, color='black', label='Exact density')
|
|
578
|
-
ax.legend(fontsize='small')
|
|
579
|
-
ax.set_ylim(bottom=0)
|
|
580
|
-
ax.set_xlim([x[0], x[-1]])
|
|
581
|
-
ax.set_xlabel(r'$\lambda$')
|
|
582
|
-
ax.set_ylabel(r'$\rho(\lambda)$''')
|
|
583
|
-
ax.set_title('Histogram of Samples from Distribution')
|
|
584
|
-
|
|
585
|
-
# Save
|
|
586
|
-
if save is False:
|
|
587
|
-
save_status = False
|
|
588
|
-
save_filename = ''
|
|
589
|
-
else:
|
|
590
|
-
save_status = True
|
|
591
|
-
if isinstance(save, str):
|
|
592
|
-
save_filename = save
|
|
593
|
-
else:
|
|
594
|
-
save_filename = 'samples.pdf'
|
|
595
|
-
|
|
596
|
-
texplot.show_or_save_plot(plt, default_filename=save_filename,
|
|
597
|
-
transparent_background=True, dpi=400,
|
|
598
|
-
show_and_save=save_status, verbose=True)
|