Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for setting tick labels #32

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", "ceter"]:
lucianosrp marked this conversation as resolved.
Show resolved Hide resolved
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
23 changes: 23 additions & 0 deletions tests/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@ 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 param == "yaxis.labellocation":
if option == "top":
self.assertEqual(option, "top")
elif option == "bottom":
self.assertEqual(option, "bottom")

lgienapp marked this conversation as resolved.
Show resolved Hide resolved
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()
Loading