Skip to content

Commit

Permalink
Allow totals_plot_elements=0 to disable totals plot
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Dec 28, 2023
1 parent 9a00998 commit 0916572
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
What's new in version 0.9
-------------------------
- Ability to disable totals plot with `totals_plot_elements=0`.

What's new in version 0.8
-------------------------

Expand Down
19 changes: 14 additions & 5 deletions upsetplot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class UpSet:
Setting to 0 is handled.
totals_plot_elements : int
The totals plot should be large enough to fit this many matrix
elements.
elements. Use totals_plot_elements=0 to disable the totals plot.
show_counts : bool or str, default=False
Whether to label the intersection size bars with the cardinality
of the intersection. When a string, this formats the number.
Expand Down Expand Up @@ -691,7 +691,9 @@ def make_grid(self, fig=None):
out = {
"matrix": gridspec[-n_cats:, -n_inters:],
"shading": gridspec[-n_cats:, :],
"totals": gridspec[-n_cats:, : self._totals_plot_elements],
"totals": None
if self._totals_plot_elements == 0
else gridspec[-n_cats:, : self._totals_plot_elements],
"gs": gridspec,
}
cumsizes = np.cumsum(sizes[::-1])
Expand All @@ -703,7 +705,9 @@ def make_grid(self, fig=None):
out = {
"matrix": gridspec[-n_inters:, :n_cats],
"shading": gridspec[:, :n_cats],
"totals": gridspec[: self._totals_plot_elements, :n_cats],
"totals": None
if self._totals_plot_elements == 0
else gridspec[: self._totals_plot_elements, :n_cats],
"gs": gridspec,
}
cumsizes = np.cumsum(sizes)
Expand Down Expand Up @@ -970,8 +974,13 @@ def plot(self, fig=None):
self.plot_shading(shading_ax)
matrix_ax = self._reorient(fig.add_subplot)(specs["matrix"], sharey=shading_ax)
self.plot_matrix(matrix_ax)
totals_ax = self._reorient(fig.add_subplot)(specs["totals"], sharey=matrix_ax)
self.plot_totals(totals_ax)
if specs["totals"] is None:
totals_ax = None
else:
totals_ax = self._reorient(fig.add_subplot)(
specs["totals"], sharey=matrix_ax
)
self.plot_totals(totals_ax)
out = {"matrix": matrix_ax, "shading": shading_ax, "totals": totals_ax}

for plot in self._subset_plots:
Expand Down
1 change: 1 addition & 0 deletions upsetplot/tests/test_upsetplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def test_param_validation(kw):
{"intersection_plot_elements": 0},
{"facecolor": "red"},
{"shading_color": "lightgrey", "other_dots_color": "pink"},
{"totals_plot_elements": 0},
],
)
def test_plot_smoke_test(kw):
Expand Down

0 comments on commit 0916572

Please sign in to comment.