Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed Feb 19, 2024
1 parent 2a4a6a1 commit 348f22c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions brokenaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -361,7 +366,9 @@ def legend(self, handles=None, labels=None, *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":
[
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down

0 comments on commit 348f22c

Please sign in to comment.