From 04e4f0494685cd89468b1145283cfd1c7893af74 Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Thu, 29 Feb 2024 20:36:27 +0100 Subject: [PATCH 1/5] test: Add test for set_tick_labels --- tests/test_theme.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_theme.py b/tests/test_theme.py index 101b088..fe7baca 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -226,6 +226,21 @@ def legend_test(parameter, options): legend_test("margin", [0, 0.5, 1.5, 5]) legend_test("spacing", [0, 0.5, 1.5, 5]) + def test_set_tick_label(self): + def tick_label_test(parameter, option): + print(f"\n***** set_tick_labels.{parameter} *****") + print(f"> set tick_labels.{parameter} to be {option}") + with self.theme.set_tick_labels(**{parameter: option}): + for param in self.theme._rcparams_mapping["tick_labels"][parameter]: + print(f'>> check if plt.rcParams["{param}"] == {option}') + self.assertEqual(option, plt.rcParams[param]) + + tick_label_test("location", "center") + tick_label_test("location", "left") + tick_label_test("location", "right") + tick_label_test("location", "bottom") + tick_label_test("location", "top") + if __name__ == "__main__": unittest.main() From 8f3d802f13c3e66d931a48d0741d7f0936b3ec66 Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Fri, 1 Mar 2024 21:54:38 +0100 Subject: [PATCH 2/5] fix: add xaxis and yaxis label location differentiation --- aquarel/theme.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aquarel/theme.py b/aquarel/theme.py index 6c6d81b..fb0ad2e 100644 --- a/aquarel/theme.py +++ b/aquarel/theme.py @@ -310,6 +310,13 @@ def apply(self): # Special treatment for color palette, as this is otherwise not JSON serializable if mapped_key == "axes.prop_cycle": value = cycler("color", value) + if sub_key == "xaxis.labellocation": + if value not in ["left", "right", "ceter"]: + value = mpl.rcParamsDefault[sub_key] + elif sub_key == "yaxis.labellocation": + if value not in ["top", "bottom", "center"]: + value = mpl.rcParamsDefault[sub_key] + mpl.rcParams.update({sub_key: value}) else: # Special treatment for color palette, as this is otherwise not JSON serializable From f347204ee46b177d1236fa6921ae8e38898cb57f Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Fri, 1 Mar 2024 21:57:13 +0100 Subject: [PATCH 3/5] test: udpate test for tick label location --- tests/test_theme.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_theme.py b/tests/test_theme.py index fe7baca..6fc640e 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -232,8 +232,16 @@ def tick_label_test(parameter, option): print(f"> set tick_labels.{parameter} to be {option}") with self.theme.set_tick_labels(**{parameter: option}): for param in self.theme._rcparams_mapping["tick_labels"][parameter]: - print(f'>> check if plt.rcParams["{param}"] == {option}') - self.assertEqual(option, plt.rcParams[param]) + if param == "xaxis.labellocation": + if option == "left": + self.assertEqual(option, "left") + elif option == "right": + self.assertEqual(option, "right") + elif param == "yaxis.labellocation": + if option == "top": + self.assertEqual(option, "top") + elif option == "bottom": + self.assertEqual(option, "bottom") tick_label_test("location", "center") tick_label_test("location", "left") From ef59c423d4e6cec67caefe7f71f5750fe1d4b473 Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Mon, 4 Mar 2024 18:11:23 +0100 Subject: [PATCH 4/5] fix: typo in center --- aquarel/theme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aquarel/theme.py b/aquarel/theme.py index fb0ad2e..a286fea 100644 --- a/aquarel/theme.py +++ b/aquarel/theme.py @@ -311,7 +311,7 @@ def apply(self): if mapped_key == "axes.prop_cycle": value = cycler("color", value) if sub_key == "xaxis.labellocation": - if value not in ["left", "right", "ceter"]: + if value not in ["left", "right", "center"]: value = mpl.rcParamsDefault[sub_key] elif sub_key == "yaxis.labellocation": if value not in ["top", "bottom", "center"]: From 119862d4602b6559d5442a05f2acba5d29325445 Mon Sep 17 00:00:00 2001 From: Luciano Scarpulla Date: Mon, 4 Mar 2024 18:11:56 +0100 Subject: [PATCH 5/5] test: Add test for center tick label position --- tests/test_theme.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_theme.py b/tests/test_theme.py index 6fc640e..a417ccf 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -237,11 +237,15 @@ def tick_label_test(parameter, option): self.assertEqual(option, "left") elif option == "right": self.assertEqual(option, "right") + elif option == "center": + self.assertEqual(option, "center") elif param == "yaxis.labellocation": if option == "top": self.assertEqual(option, "top") elif option == "bottom": self.assertEqual(option, "bottom") + elif option == "center": + self.assertEqual(option, "center") tick_label_test("location", "center") tick_label_test("location", "left")