Commit b1a7a61d authored by connor.hainje@pnnl.gov's avatar connor.hainje@pnnl.gov
Browse files

Bugfix in get center coordinates, allow specifying x and y as zero

parent db7cbf58
......@@ -27,8 +27,8 @@ def get_center_coordinates(fig):
x_lo = min([b["xmin"] for b in bounds])
y_lo = min([b["ymin"] for b in bounds])
x_hi = min([b["xmax"] for b in bounds])
y_hi = min([b["ymax"] for b in bounds])
x_hi = max([b["xmax"] for b in bounds])
y_hi = max([b["ymax"] for b in bounds])
x_center = 0.5 * (x_lo + x_hi)
y_center = 0.5 * (y_lo + y_hi)
......@@ -54,8 +54,8 @@ def better_xlabel(fig, label, loc="bottom", x=None, y=None, fontsize=16):
fontsize : int, optional
The fontsize of the label, by default 16
"""
x_val = x if x else get_center_coordinates(fig)[0]
y_val = y if y else (1.0 if loc == "top" else 0.0)
x_val = x if x is not None else get_center_coordinates(fig)[0]
y_val = y if y is not None else (1.0 if loc == "top" else 0.0)
vert_align = "top" if loc == "bottom" else ("bottom" if loc == "top" else "center")
kwargs = dict(fontsize=fontsize, ha="center", va=vert_align)
fig.text(x_val, y_val, label, **kwargs)
......@@ -80,8 +80,8 @@ def better_ylabel(fig, label, loc="left", x=None, y=None, fontsize=16):
fontsize : int, optional
The fontsize of the label, by default 16
"""
x_val = x if x else (1.0 if loc == "right" else 0.0)
y_val = y if y else get_center_coordinates(fig)[1]
x_val = x if x is not None else (1.0 if loc == "right" else 0.0)
y_val = y if y is not None else get_center_coordinates(fig)[1]
horiz_align = "right" if loc == "left" else ("left" if loc == "right" else "center")
kwargs = dict(fontsize=fontsize, ha=horiz_align, va="center", rotation="vertical")
fig.text(x_val, y_val, label, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment