From 90dbfab5b919499ba10fd5752c71410bd1aa59a7 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Thu, 11 Jan 2024 16:55:34 +0100 Subject: [PATCH 1/5] Changed color and label of magnification second Y-axis --- examples/example_16/ulens_model_fit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 697b982d..364ebd11 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3098,8 +3098,8 @@ def _mark_second_Y_axis_in_best_plot(self): """ settings = self._plots['best model']["second Y scale"] magnifications = settings['magnifications'] - color = settings.get("color", "red") - label = settings.get("label", "magnification") + color = settings.get("color", "black") + label = settings.get("label", "Magnification") labels = settings.get("labels") ylim = plt.ylim() From d0b1f48238a63326526eecd81b9e59878bd775f3 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Thu, 18 Jan 2024 16:31:06 +0100 Subject: [PATCH 2/5] Changed magnification ticks to inside, minor ticks TBD --- examples/example_16/ulens_model_fit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 364ebd11..41ee064a 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3120,8 +3120,8 @@ def _mark_second_Y_axis_in_best_plot(self): ax2.set_ylabel(label).set_color(color) ax2.spines['right'].set_color(color) ax2.set_ylim(ylim[0], ylim[1]) - ax2.tick_params(axis='y', colors=color) - plt.yticks(ticks, labels, color=color) + ax2.tick_params(axis='y', direction="in", which="major", colors=color) + plt.yticks(ticks, labels, color=color) # , minor=True) def _second_Y_axis_get_fluxes(self, ylim): """ From c118a294d446dd202dd5354aa4a2a7b3cc807a0d Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Sat, 20 Jan 2024 21:09:01 +0100 Subject: [PATCH 3/5] Minor ticks for magnification axis, example16 --- examples/example_16/ulens_model_fit.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 41ee064a..d058b17e 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -38,7 +38,7 @@ except Exception: raise ImportError('\nYou have to install MulensModel first!\n') -__version__ = '0.34.3' +__version__ = '0.34.4' class UlensModelFit(object): @@ -3109,7 +3109,10 @@ def _mark_second_Y_axis_in_best_plot(self): if magnifications == "optimal": (magnifications, labels, out1) = self._second_Y_axis_optimal( ax2, A_min, A_max) - flux = sb_fluxes[0] * magnifications + sb_fluxes[1] + minor_ticks = self._second_Y_axis_minor_ticks(ax2, magnifications, + sb_fluxes) + ax2.set_yticks(minor_ticks, color=color, minor=True) + flux = sb_fluxes[0] * np.array(magnifications) + sb_fluxes[1] out2 = self._second_Y_axis_warnings(flux, labels, magnifications, A_min, A_max) if out1 or out2: @@ -3120,8 +3123,8 @@ def _mark_second_Y_axis_in_best_plot(self): ax2.set_ylabel(label).set_color(color) ax2.spines['right'].set_color(color) ax2.set_ylim(ylim[0], ylim[1]) - ax2.tick_params(axis='y', direction="in", which="major", colors=color) - plt.yticks(ticks, labels, color=color) # , minor=True) + ax2.tick_params(axis='y', direction="in", which="both", colors=color) + ax2.set_yticks(ticks, labels, color=color) def _second_Y_axis_get_fluxes(self, ylim): """ @@ -3188,6 +3191,19 @@ def _second_Y_axis_warnings(self, flux, labels, A_values, A_min, A_max): return False + def _second_Y_axis_minor_ticks(self, ax2, A_values, sb_fluxes): + """ + Get minor ticks for magnification axis from matplotlib + """ + ax2.minorticks_on() + minor_ticks_A = ax2.yaxis.get_ticklocs(minor=True) + minor_ticks_A = minor_ticks_A[~np.isin(minor_ticks_A, A_values)] + + minor_ticks_flux = sb_fluxes[0] * minor_ticks_A + sb_fluxes[1] + minor_ticks_mag = mm.Utils.get_mag_from_flux(minor_ticks_flux) + + return minor_ticks_mag + def _make_trajectory_plot(self): """ make and save plot of the best trajectory From 7f0f210d8e28f1ea70954b3b1356605dc0ee29fe Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Thu, 7 Mar 2024 15:53:57 +0100 Subject: [PATCH 4/5] Applied Radek suggestions to second Y-axis --- examples/example_16/ulens_model_fit.py | 67 ++++++++++++++------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index d058b17e..12ad3511 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3096,35 +3096,41 @@ def _mark_second_Y_axis_in_best_plot(self): Mark the second (right-hand side) scale for Y axis in the best model plot """ - settings = self._plots['best model']["second Y scale"] - magnifications = settings['magnifications'] - color = settings.get("color", "black") - label = settings.get("label", "Magnification") - labels = settings.get("labels") - - ylim = plt.ylim() - ax2 = plt.gca().twinx() - (A_min, A_max, sb_fluxes) = self._second_Y_axis_get_fluxes(ylim) + (magnifications, labels, ylim, ax2) = self._second_Y_axis_settings() + (A_range, ref_fluxes) = self._second_Y_axis_get_fluxes(ylim) out1, out2 = False, False if magnifications == "optimal": (magnifications, labels, out1) = self._second_Y_axis_optimal( - ax2, A_min, A_max) - minor_ticks = self._second_Y_axis_minor_ticks(ax2, magnifications, - sb_fluxes) - ax2.set_yticks(minor_ticks, color=color, minor=True) - flux = sb_fluxes[0] * np.array(magnifications) + sb_fluxes[1] + ax2, *A_range) + self._second_Y_axis_minor_ticks(ax2, magnifications, ref_fluxes) + flux = ref_fluxes[0] * np.array(magnifications) + ref_fluxes[1] out2 = self._second_Y_axis_warnings(flux, labels, magnifications, - A_min, A_max) + *A_range) if out1 or out2: ax2.get_yaxis().set_visible(False) return ticks = mm.Utils.get_mag_from_flux(flux) + ax2.set_yticks(ticks, labels) + ax2.set_ylim(ylim[0], ylim[1]) + + def _second_Y_axis_settings(self): + """ + Get and apply settings for the second Y axis + """ + settings = self._plots['best model']["second Y scale"] + magnifications = settings['magnifications'] + color = settings.get("color", "black") + label = settings.get("label", "Magnification") + labels = settings.get("labels") + ylim = plt.ylim() + + ax2 = plt.gca().twinx() ax2.set_ylabel(label).set_color(color) ax2.spines['right'].set_color(color) - ax2.set_ylim(ylim[0], ylim[1]) ax2.tick_params(axis='y', direction="in", which="both", colors=color) - ax2.set_yticks(ticks, labels, color=color) + + return (magnifications, labels, ylim, ax2) def _second_Y_axis_get_fluxes(self, ylim): """ @@ -3138,7 +3144,7 @@ def _second_Y_axis_get_fluxes(self, ylim): A_min = (flux_min - blend_flux) / total_source_flux A_max = (flux_max - blend_flux) / total_source_flux - return (A_min, A_max, [total_source_flux, blend_flux]) + return ([A_min, A_max], [total_source_flux, blend_flux]) def _second_Y_axis_optimal(self, ax2, A_min, A_max): """ @@ -3166,6 +3172,18 @@ def _second_Y_axis_optimal(self, ax2, A_min, A_max): return (A_values[fnum < 4], labels[fnum < 4].tolist(), False) + def _second_Y_axis_minor_ticks(self, ax2, A_values, sb_fluxes): + """ + Get minor ticks for magnification axis from matplotlib + """ + ax2.minorticks_on() + minor_ticks_A = ax2.yaxis.get_ticklocs(minor=True) + minor_ticks_A = minor_ticks_A[~np.isin(minor_ticks_A, A_values)] + + minor_ticks_flux = sb_fluxes[0] * minor_ticks_A + sb_fluxes[1] + minor_ticks_mag = mm.Utils.get_mag_from_flux(minor_ticks_flux) + ax2.set_yticks(minor_ticks_mag, minor=True) + def _second_Y_axis_warnings(self, flux, labels, A_values, A_min, A_max): """ Issue warnings for negative flux or bad range of magnificaitons @@ -3191,19 +3209,6 @@ def _second_Y_axis_warnings(self, flux, labels, A_values, A_min, A_max): return False - def _second_Y_axis_minor_ticks(self, ax2, A_values, sb_fluxes): - """ - Get minor ticks for magnification axis from matplotlib - """ - ax2.minorticks_on() - minor_ticks_A = ax2.yaxis.get_ticklocs(minor=True) - minor_ticks_A = minor_ticks_A[~np.isin(minor_ticks_A, A_values)] - - minor_ticks_flux = sb_fluxes[0] * minor_ticks_A + sb_fluxes[1] - minor_ticks_mag = mm.Utils.get_mag_from_flux(minor_ticks_flux) - - return minor_ticks_mag - def _make_trajectory_plot(self): """ make and save plot of the best trajectory From 323976b24ad1f372e050646e6aeb4623d0a6eb29 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Fri, 8 Mar 2024 11:44:58 +0100 Subject: [PATCH 5/5] Renaming sb_fluxes to ref_fluxes, example_16 --- examples/example_16/ulens_model_fit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 12ad3511..23769d12 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -3172,7 +3172,7 @@ def _second_Y_axis_optimal(self, ax2, A_min, A_max): return (A_values[fnum < 4], labels[fnum < 4].tolist(), False) - def _second_Y_axis_minor_ticks(self, ax2, A_values, sb_fluxes): + def _second_Y_axis_minor_ticks(self, ax2, A_values, ref_fluxes): """ Get minor ticks for magnification axis from matplotlib """ @@ -3180,7 +3180,7 @@ def _second_Y_axis_minor_ticks(self, ax2, A_values, sb_fluxes): minor_ticks_A = ax2.yaxis.get_ticklocs(minor=True) minor_ticks_A = minor_ticks_A[~np.isin(minor_ticks_A, A_values)] - minor_ticks_flux = sb_fluxes[0] * minor_ticks_A + sb_fluxes[1] + minor_ticks_flux = ref_fluxes[0] * minor_ticks_A + ref_fluxes[1] minor_ticks_mag = mm.Utils.get_mag_from_flux(minor_ticks_flux) ax2.set_yticks(minor_ticks_mag, minor=True)