From 5d4673dbaba053eb4a59d9a2ffb78c29ede7dbb5 Mon Sep 17 00:00:00 2001 From: John Muradeli Date: Sat, 21 Oct 2023 15:27:55 +0400 Subject: [PATCH 1/4] Auto-generate `C_lut.npy`; basic `.gitignore` --- .gitignore | 4 ++++ complex_colormap/cplot.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..749ccda --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class diff --git a/complex_colormap/cplot.py b/complex_colormap/cplot.py index 1bd8ade..c55e429 100644 --- a/complex_colormap/cplot.py +++ b/complex_colormap/cplot.py @@ -21,7 +21,18 @@ new_space = "JCh" # 2D C vs (J, h) -C_lut = np.load(os.path.join(os.path.dirname(__file__), 'C_lut.npy')) +# if not generated yet, generate it +try: + C_lut = np.load(os.path.join(os.path.dirname(__file__), 'C_lut.npy')) +except: + import sys + from subprocess import PIPE, Popen + # run file while printing outputs in real-time + cmd = [sys.executable, '-u', + os.path.join(os.path.dirname(__file__), 'generation.py')] + with Popen(cmd, bufsize=1, stdout=PIPE, text=True) as sub: + for line in sub.stdout: + print(line, end='') # TODO: -360 to +360 is overkill for -180 to +180, just need a little extra max_J_vals = np.linspace(0, 100, C_lut.shape[0], endpoint=True) From 380c1f747d65105385b834cdf3ca51057076c242 Mon Sep 17 00:00:00 2001 From: John Muradeli Date: Sat, 21 Oct 2023 15:37:03 +0400 Subject: [PATCH 2/4] better progress bar --- complex_colormap/generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/complex_colormap/generation.py b/complex_colormap/generation.py index 6c4a3ca..38bc025 100644 --- a/complex_colormap/generation.py +++ b/complex_colormap/generation.py @@ -143,7 +143,7 @@ def create_C_lut(): C_lut = np.ones((J_lutsize, h_lutsize)) for n, J in enumerate(J_vals): - print('J =', J) + print('J = {:<6.4g} ({}/{})'.format(J, n + 1, len(J_vals))) for m, h in enumerate(h_vals): C = find_wall(J, h) C_lut[n, m] = C From da216de2eb8d41d120e51e0069791d5edcc5e02b Mon Sep 17 00:00:00 2001 From: John Muradeli Date: Sat, 21 Oct 2023 17:05:57 +0400 Subject: [PATCH 3/4] Update cplot.py --- complex_colormap/cplot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/complex_colormap/cplot.py b/complex_colormap/cplot.py index c55e429..a4940c3 100644 --- a/complex_colormap/cplot.py +++ b/complex_colormap/cplot.py @@ -21,10 +21,9 @@ new_space = "JCh" # 2D C vs (J, h) -# if not generated yet, generate it -try: - C_lut = np.load(os.path.join(os.path.dirname(__file__), 'C_lut.npy')) -except: +loadpath = os.path.join(os.path.dirname(__file__), 'C_lut.npy') +if not os.path.isfile(loadpath): + # if not generated yet, generate it import sys from subprocess import PIPE, Popen # run file while printing outputs in real-time @@ -33,6 +32,9 @@ with Popen(cmd, bufsize=1, stdout=PIPE, text=True) as sub: for line in sub.stdout: print(line, end='') +# load +C_lut = np.load(loadpath) + # TODO: -360 to +360 is overkill for -180 to +180, just need a little extra max_J_vals = np.linspace(0, 100, C_lut.shape[0], endpoint=True) From 42fd390de13792ee42e195889b2366b7fda46dff Mon Sep 17 00:00:00 2001 From: John Muradeli Date: Sat, 21 Oct 2023 17:11:27 +0400 Subject: [PATCH 4/4] fig title --- complex_colormap/cplot.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/complex_colormap/cplot.py b/complex_colormap/cplot.py index a4940c3..ecd4100 100644 --- a/complex_colormap/cplot.py +++ b/complex_colormap/cplot.py @@ -185,7 +185,7 @@ def max_chroma_colormap(z, nancolor='gray'): def cplot(f, re=(-5, 5), im=(-5, 5), points=160000, color='const', file=None, - dpi=None, axes=None): + dpi=None, axes=None, title=None): r""" Plot a complex function using lightness for magnitude and hue for phase @@ -219,6 +219,8 @@ def cplot(f, re=(-5, 5), im=(-5, 5), points=160000, color='const', file=None, ‘figure’, it will set the dpi to be the value of the figure. axes : matplotlib.axes._subplots.AxesSubplot An existing axes object in which to place the plot. + title : str + Passed to `ax.set_title`. Returns ------- @@ -307,6 +309,8 @@ def cplot(f, re=(-5, 5), im=(-5, 5), points=160000, color='const', file=None, axes.imshow(w, extent=(re_lo, re_hi, im_lo, im_hi), origin='lower') axes.set_xlabel('$\operatorname{Re}(z)$') axes.set_ylabel('$\operatorname{Im}(z)$') + if title: + axes.set_title(title) if fig: if file: plt.savefig(file, dpi=dpi) @@ -317,8 +321,6 @@ def cplot(f, re=(-5, 5), im=(-5, 5), points=160000, color='const', file=None, if __name__ == '__main__': - cplot(lambda z: z, color='max') - plt.title('$f(z) = z$') - - cplot(lambda z: z, color='const') - plt.title('$f(z) = z$') + title = '$f(z) = z$' + cplot(lambda z: z, title=title + ' | max', color='max') + cplot(lambda z: z, title=title + ' | const', color='const')