Skip to content

Commit

Permalink
Merge pull request #32 from lucianosrp/fix/set-tick-labels
Browse files Browse the repository at this point in the history
🐛 Fix #25
  • Loading branch information
lgienapp authored Mar 4, 2024
2 parents e8b3764 + 119862d commit 73a7642
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aquarel/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "center"]:
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
Expand Down
27 changes: 27 additions & 0 deletions tests/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,33 @@ 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]:
if param == "xaxis.labellocation":
if option == "left":
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")
tick_label_test("location", "right")
tick_label_test("location", "bottom")
tick_label_test("location", "top")


if __name__ == "__main__":
unittest.main()

0 comments on commit 73a7642

Please sign in to comment.