Skip to content

Commit

Permalink
Merge pull request #106 from huangy6/huangy6-patch-1
Browse files Browse the repository at this point in the history
Fix large x-axis plot margins with high number of unique intersections
  • Loading branch information
jnothman committed Apr 26, 2021
2 parents e6f6688 + 291b917 commit a7ae318
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions upsetplot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,13 @@ def plot_matrix(self, ax):
if not self._horizontal:
ax.yaxis.set_ticks_position('top')
ax.set_frame_on(False)
ax.set_xlim(xmin=.5, xmax=x[-1] + .5, auto=False)

def plot_intersections(self, ax):
"""Plot bars indicating intersection size
"""
ax = self._reorient(ax)
ax.set_autoscalex_on(False)
rects = ax.bar(np.arange(len(self.intersections)), self.intersections,
.5, color=self._facecolor, zorder=10, align='center')

Expand Down
16 changes: 16 additions & 0 deletions upsetplot/tests/test_upsetplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,19 @@ def test_index_must_be_bool(x):
x = x.set_index(['cat0', 'cat1', 'cat2']).iloc[:, 0]
with pytest.raises(ValueError, match='not boolean'):
UpSet(x)


@pytest.mark.parametrize('x', [
generate_counts(n_categories=3),
generate_counts(n_categories=8),
generate_counts(n_categories=15),
])
def test_matrix_plot_margins(x):
"""Non-regression test addressing a bug where there is are large whitespace
margins around the matrix when the number of intersections is large"""
axes = plot(x)

# Expected behavior is that each matrix column takes up one unit on x-axis
expected = len(x) - 1
actual = axes['matrix'].get_xlim()[1] - axes['matrix'].get_xlim()[0]
assert expected == actual

0 comments on commit a7ae318

Please sign in to comment.