Skip to content

Commit

Permalink
Spines (#112)
Browse files Browse the repository at this point in the history
* refactor: rmv CallCurator

* get spines and set properties of those spines

* add test image

* simplify spines code
  • Loading branch information
bendichter committed Feb 20, 2024
1 parent b2cb1c5 commit 692446a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions brokenaxes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from typing import Optional

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(
for the discontinuities.
"""

self._spines = None
self.diag_color = diag_color
self.despine = despine
self.d = d
Expand Down Expand Up @@ -424,6 +426,17 @@ def text(self, x, y, s, *args, **kwargs):

raise ValueError("(x,y) coordinate of text not within any axes")

@property
def spines(self):
if self._spines is None:
self._spines = dict(
top=[ax.spines["top"] for ax in self.axs if ax.get_subplotspec().is_first_row()],
right=[ax.spines["right"] for ax in self.axs if ax.get_subplotspec().is_last_col()],
bottom=[ax.spines["bottom"] for ax in self.axs if ax.get_subplotspec().is_last_row()],
left=[ax.spines["left"] for ax in self.axs if ax.get_subplotspec().is_first_col()],
)
return self._spines


def brokenaxes(*args, **kwargs):
"""Convenience method for `BrokenAxes` class.
Expand Down
12 changes: 12 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ def test_draw_diags():
return fig


@pytest.mark.mpl_image_compare
def test_set_spine_prop():
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
)

[x.set_linewidth(2) for x in bax.spines["bottom"]]

return fig


def test_get_axis_special():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
Expand Down
Binary file added test_baseline/test_set_spine_prop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 692446a

Please sign in to comment.