API Reference#

UpSetAltair#

Configuration#

altair_upset.UpSetAltair(data, sets, *, title='', subtitle='', abbre=None, sort_by='frequency', sort_order='ascending', width=1200, height=700, height_ratio=0.6, horizontal_bar_chart_width=None, color_range=['#55A8DB', '#3070B5', '#30363F', '#F1AD60', '#DF6234', '#BDC6CA'], highlight_color='#EA4667', glyph_size=100, set_label_bg_size=500, line_connection_size=1, horizontal_bar_size=20, vertical_bar_label_size=16, vertical_bar_padding=20, theme=None)#

Generate interactive UpSet plots using Altair. [Lex et al., 2014]_

UpSet plots are used to visualize set intersections in a more scalable way than Venn diagrams. This implementation provides interactive features like hover highlighting and legend filtering.

Parameters:
  • data (pandas.DataFrame) – Input data where each column represents a set and contains binary values (0 or 1). Each row represents an element, and the columns indicate set membership.

  • sets (list of str) – Names of the sets to visualize (must correspond to column names in data).

  • title (str, default "") – Title of the plot.

  • subtitle (str or list of str, default "") – Subtitle(s) of the plot. Can be a single string or list of strings for multiple lines.

  • abbre (list of str, optional) – Abbreviations for set names (must have same length as sets).

  • sort_by ({"frequency", "degree"}, default "frequency") – Method to sort the intersections: - “frequency”: sort by intersection size - “degree”: sort by number of sets in intersection

  • sort_order ({"ascending", "descending"}, default "ascending") – Order of sorting for intersections.

  • width (int, default 1200) – Total width of the plot in pixels.

  • height (int, default 700) – Total height of the plot in pixels.

  • height_ratio (float, default 0.6) – Ratio of vertical bar chart height to total height (between 0 and 1).

  • horizontal_bar_chart_width (int, default 300) – Width of the horizontal bar chart in pixels.

  • color_range (list of str) – List of colors for the sets. Defaults to a colorblind-friendly palette.

  • highlight_color (str, default "#EA4667") – Color used for highlighting on hover.

  • glyph_size (int, default 200) – Size of the matrix glyphs in pixels.

  • set_label_bg_size (int, default 1000) – Size of the set label background circles.

  • line_connection_size (int, default 2) – Thickness of connecting lines in pixels.

  • horizontal_bar_size (int, default 20) – Height of horizontal bars in pixels.

  • vertical_bar_label_size (int, default 16) – Font size of vertical bar labels.

  • vertical_bar_padding (int, default 20) – Padding between vertical bars.

  • theme (str, optional) – Altair theme to use. If None, uses the current default theme.

Returns:

An Altair chart object representing the UpSet plot.

Return type:

altair.Chart

Examples

>>> import altair_upset as au
>>> import pandas as pd
>>> data = pd.DataFrame({
...     'set1': [1, 0, 1],
...     'set2': [1, 1, 0],
...     'set3': [0, 1, 1]
... })
>>> chart = au.UpSetAltair(
...     data=data,
...     sets=["set1", "set2", "set3"],
...     title="Sample UpSet Plot"
... )

Notes

The plot consists of three main components: 1. A matrix view showing set intersections 2. A vertical bar chart showing intersection sizes 3. A horizontal bar chart showing set sizes

References

altair_upset.upsetaltair_top_level_configuration(base, legend_orient='top-left', legend_symbol_size=30)#