From b4d50cf33dadcd84ad71af66b828d900b63911af Mon Sep 17 00:00:00 2001 From: Sarthak Jariwala Date: Mon, 4 Jan 2021 17:26:53 -0800 Subject: [PATCH] fix location validation; add tests for checking rcParam updates --- matplotlib_scalebar/scalebar.py | 1 + matplotlib_scalebar/test_scalebar.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 3540e6f..55e4b1f 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -89,6 +89,7 @@ def _validate_legend_loc(loc): rc = matplotlib.RcParams() rc["legend.loc"] = loc + return loc defaultParams.update( { diff --git a/matplotlib_scalebar/test_scalebar.py b/matplotlib_scalebar/test_scalebar.py index 2642cda..1a61e97 100644 --- a/matplotlib_scalebar/test_scalebar.py +++ b/matplotlib_scalebar/test_scalebar.py @@ -38,6 +38,33 @@ def scalebar(): plt.draw() +def test_mpl_rcParams_update(): + """ + Test if scalebar params are updated accurately in matplotlib rcParams + """ + + params = { + "scalebar.length_fraction": 0.2, + "scalebar.height_fraction": 0.01, # deprecated + "scalebar.width_fraction": 0.01, + "scalebar.location": "upper right", + "scalebar.pad": 0.2, + "scalebar.border_pad": 0.1, + "scalebar.sep": 5, + "scalebar.frameon": True, + "scalebar.color": "k", + "scalebar.box_color": "w", + "scalebar.box_alpha": 1.0, + "scalebar.scale_loc": "bottom", + "scalebar.label_loc": "top", + "scalebar.rotation": "horizontal", + } + matplotlib.rcParams.update(params) + + for key, value in params.items(): + assert matplotlib.rcParams[key] == value + + def test_scalebar_dx_m(scalebar): assert scalebar.get_dx() == pytest.approx(0.5, abs=1e-2) assert scalebar.dx == pytest.approx(0.5, abs=1e-2)