Skip to content

Commit

Permalink
Merge pull request #27 from SarthakJariwala/v0.3.x
Browse files Browse the repository at this point in the history
scalebar properties can be set with parameters in `set_scalebar`
  • Loading branch information
SarthakJariwala authored Aug 19, 2020
2 parents 9d99eeb + 86c101f commit 53dc2d1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 120 deletions.
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "seaborn-image"
version = "0.3.1"
version = "0.3.2"
description = "seaborn-image: image data visualization and processing like seaborrn using matplotlib, scipy and scikit-image"
authors = ["Sarthak Jariwala <[email protected]>"]
license = "MIT"
Expand Down
42 changes: 31 additions & 11 deletions src/seaborn_image/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_context(mode="talk", fontfamily="arial", fontweight="bold", rc=None):
>>> isns.set_context(rc={"axes.edgecolor": "red"})
"""
# plt.rc("axes.spines", left=False, right=False, top=False, bottom=False)

if mode == "paper":
plt.rc("axes", linewidth=1.5)
plt.rc("axes", titlesize=15, titleweight=fontweight)
Expand Down Expand Up @@ -116,26 +116,46 @@ def set_image(cmap="ice", origin="lower", interpolation="nearest"):
plt.rc("image", cmap=cmap, origin=origin, interpolation=interpolation)


def set_scalebar(rc=None): # TODO re-write input as individual kwargs instead of dict
def set_scalebar(
color="white",
location="lower right",
height_fraction=0.025,
length_fraction=0.3,
scale_loc="top",
box_alpha=0,
rc=None,
):
"""Set scalebar properties such as color, scale_loc,
height_fraction, length_fraction, box_alpha, etc
height_fraction, length_fraction, box_alpha, etc.
To pass more properties that are not specified as key word
argument, use the `rc` parameter. Refer to https://github.com/ppinard/matplotlib-scalebar
for more information on additional parameters.
Args:
color(str, optional): color of the scalebar. Defaults to "white".
location (str, optional): scalebar location on the image (same as `matplotlib` legend).
Defaults to "lower right".
height_fraction (float, optional): Defaults to 0.025.
length_fraction (float, optional): Defaults to 0.3
scale_loc (str, optional): location of the scale number and units with respect to the bar.
Defaults to "top".
box_alpha (float, optional): transparency of the box that contains the scalebar artist.
Defaults to 0.
rc (dict, optional): dictionary of scalebar properties to be set.
Defaults to None.
Example:
>>> import seaborn_image as isns
>>> isns.set_scalebar({"color":"red"})
>>> isns.set_scalebar({"scale_loc":"bottom"})
>>> isns.set_scalebar(color = "red")
>>> isns.set_scalebar(scale_loc = "bottom")
"""
mpl.rcParams.update({"scalebar.color": "white"})
mpl.rcParams.update({"scalebar.height_fraction": 0.05})
mpl.rcParams.update({"scalebar.length_fraction": 0.3})
mpl.rcParams.update({"scalebar.scale_loc": "top"})
mpl.rcParams.update({"scalebar.location": "lower right"})
mpl.rcParams.update({"scalebar.box_alpha": 0})
mpl.rcParams.update({"scalebar.color": color})
mpl.rcParams.update({"scalebar.height_fraction": height_fraction})
mpl.rcParams.update({"scalebar.length_fraction": length_fraction})
mpl.rcParams.update({"scalebar.scale_loc": scale_loc})
mpl.rcParams.update({"scalebar.location": location})
mpl.rcParams.update({"scalebar.box_alpha": box_alpha})

if rc is not None:
assert isinstance(rc, dict), "'rc' must be a dict"
Expand Down
33 changes: 25 additions & 8 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,30 @@ def test_set_image(cmap, origin, interpolation):
assert mpl.rcParams["image.interpolation"] == interpolation


def test_set_scalebar():
isns.set_scalebar()
@pytest.mark.parametrize("color", ["white", "k", "C4"])
@pytest.mark.parametrize("height_fraction", [0.025])
@pytest.mark.parametrize("length_fraction", [0.3])
@pytest.mark.parametrize("scale_loc", ["top", "bottom"])
@pytest.mark.parametrize("location", ["upper right", "center"])
@pytest.mark.parametrize("box_alpha", [0, 0.4])
def test_set_scalebar(
color, height_fraction, length_fraction, scale_loc, location, box_alpha
):
isns.set_scalebar(
color=color,
height_fraction=height_fraction,
length_fraction=length_fraction,
scale_loc=scale_loc,
location=location,
box_alpha=box_alpha,
)

assert mpl.rcParams["scalebar.color"] == "white"
assert mpl.rcParams["scalebar.height_fraction"] == 0.05
assert mpl.rcParams["scalebar.length_fraction"] == 0.3
assert mpl.rcParams["scalebar.scale_loc"] == "top"
assert mpl.rcParams["scalebar.location"] == "lower right"
assert mpl.rcParams["scalebar.box_alpha"] == 0
assert mpl.rcParams["scalebar.color"] == color
assert mpl.rcParams["scalebar.height_fraction"] == height_fraction
assert mpl.rcParams["scalebar.length_fraction"] == length_fraction
assert mpl.rcParams["scalebar.scale_loc"] == scale_loc
assert mpl.rcParams["scalebar.location"] == location
assert mpl.rcParams["scalebar.box_alpha"] == box_alpha


def test_set_context_w_rc():
Expand All @@ -75,6 +90,7 @@ def test_scalebar_w_rc():
"scale_loc": "bottom",
"location": "upper right",
"box_alpha": 1,
"label_loc": "top"
}
)

Expand All @@ -84,6 +100,7 @@ def test_scalebar_w_rc():
assert mpl.rcParams["scalebar.scale_loc"] == "bottom"
assert mpl.rcParams["scalebar.location"] == "upper right"
assert mpl.rcParams["scalebar.box_alpha"] == 1
assert mpl.rcParams["scalebar.label_loc"] == "top"


def test_rc_assertion():
Expand Down
61 changes: 0 additions & 61 deletions tests/travis_install.sh

This file was deleted.

0 comments on commit 53dc2d1

Please sign in to comment.