From 582f0672b0c894bb2eeba4da74e988a944683f13 Mon Sep 17 00:00:00 2001 From: Ben Dichter Date: Mon, 19 Feb 2024 16:56:26 -0500 Subject: [PATCH] Improve coverage (#108) * refactor: rmv CallCurator * improve coverage * improve coverage --- brokenaxes.py | 19 +++++++++++++------ test.py | 12 ++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/brokenaxes.py b/brokenaxes.py index 610bf27..579138e 100644 --- a/brokenaxes.py +++ b/brokenaxes.py @@ -157,12 +157,13 @@ def __init__( if d: self.draw_diags() self.set_spines() + self.diag_handles = [] @staticmethod def draw_diag(ax, xpos, xlen, ypos, ylen, **kwargs): return ax.plot((xpos - xlen, xpos + xlen), (ypos - ylen, ypos + ylen), **kwargs) - def draw_diags(self): + def draw_diags(self, d=None, tilt=None): """ Parameters @@ -172,6 +173,10 @@ def draw_diags(self): tilt: float Angle of diagonal split mark """ + if d is not None: + self.d = d + if tilt is not None: + self.tilt = tilt size = self.fig.get_size_inches() ylen = self.d * np.sin(self.tilt * np.pi / 180) * size[0] / size[1] xlen = self.d * np.cos(self.tilt * np.pi / 180) @@ -315,6 +320,9 @@ def __getattr__(self, method): "get_second_yaxis", "get_second_xaxis", "get_legend", + "get_title", + "get_xlabel", + "get_ylabel", ]: return getattr(self.big_ax, method) @@ -358,10 +366,9 @@ def legend(self, handles=None, labels=None, *args, **kwargs): labels = l return self.big_ax.legend(handles=handles, labels=labels, *args, **kwargs) - def axis(self, *args, **kwargs): - [ax.axis(*args, **kwargs) for ax in self.axs] - - def secondary_yaxis(self, location="right", functions=None, label=None, labelpad=30): + def secondary_yaxis( + self, location="right", functions=None, label=None, labelpad=30 + ): assert location in ["right", "left"], "location must be 'right' or 'left'" if location == "right": [ @@ -420,7 +427,7 @@ def text(self, x, y, s, *args, **kwargs): ax.text(x, y, s, *args, **kwargs) return - raise ValueError('(x,y) coordinate of text not within any axes') + raise ValueError("(x,y) coordinate of text not within any axes") def brokenaxes(*args, **kwargs): diff --git a/test.py b/test.py index 6474961..4390389 100644 --- a/test.py +++ b/test.py @@ -165,10 +165,10 @@ def test_secondary_axes(): bax = brokenaxes( xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05 ) - bax.secondary_xaxis("top") + bax.secondary_xaxis("top", label="top") print(type(isinstance(bax.secondary_xaxis(), mpl.axis.XAxis))) bax.secondary_xaxis("bottom") - bax.secondary_yaxis("left") + bax.secondary_yaxis("left", label="left") bax.secondary_yaxis("right") @@ -181,3 +181,11 @@ def test_get_axis_special(): assert isinstance(bax.get_shared_x_axes(), mpl.cbook.GrouperView) assert isinstance(bax.get_xaxis(), mpl.axis.XAxis) assert isinstance(bax.get_shared_y_axes(), mpl.cbook.GrouperView) + + +def test_draw_diags(): + fig = plt.figure(figsize=(5, 2)) + bax = brokenaxes( + xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05 + ) + bax.draw_diags(tilt=90, d=.05)