Skip to content

Commit

Permalink
adds plot_upset function to the InteractionValues
Browse files Browse the repository at this point in the history
  • Loading branch information
mmschlk committed Dec 15, 2024
1 parent ed8ce7c commit 9e35aa3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions shapiq/interaction_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,15 @@ def plot_sentence(
from shapiq.plot.sentence import sentence_plot

return sentence_plot(self, words, show=show, **kwargs)

def plot_upset(self, show: bool = True, **kwargs) -> Optional[plt.Figure]:
"""Plots the upset plot.
For arguments, see shapiq.plot.upset_plot().
Returns:
The upset plot as a matplotlib figure (if show is ``False``).
"""
from shapiq.plot.upset import upset_plot

return upset_plot(self, show=show, **kwargs)
13 changes: 9 additions & 4 deletions tests/tests_plots/test_upset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@ def test_upset_plot():
assert isinstance(fig, plt.Figure)
plt.close("all")

fp = upset_plot(iv, feature_names=feature_names, color_matrix=True, show=True)
assert fp is None
fig = upset_plot(iv, feature_names=feature_names, color_matrix=True, show=True)
assert fig is None
plt.close("all")

# in the following feature 3 is not shown
fp = upset_plot(iv, n_interactions=5, all_features=False, show=False)
fig = upset_plot(iv, n_interactions=5, all_features=False, show=False)
assert isinstance(fig, plt.Figure)
plt.close("all")

# in the following feature 3 is shown
fp = upset_plot(iv, n_interactions=5, all_features=True, show=False)
fig = upset_plot(iv, n_interactions=5, all_features=True, show=False)
assert isinstance(fig, plt.Figure)
plt.close("all")

# test once directly from the interaction values
fig = iv.plot_upset(feature_names=feature_names, show=False)
assert isinstance(fig, plt.Figure)
plt.close("all")

0 comments on commit 9e35aa3

Please sign in to comment.