Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coverage #108

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 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 @@ -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)

Expand Down Expand Up @@ -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":
[
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
12 changes: 10 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 All @@ -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)
Loading