Logo

OVERVIEW

  • Introduction
  • Contributing
  • Docstring Style Guide
  • Usage Principles
  • Evaluation

EXAMPLES

  • Tutorials

REFERENCES

  • API
    • Data Handling
    • Sequence Analysis
      • aaanalysis.AAlogo
      • aaanalysis.AAlogoPlot
        • AAlogoPlot
        • aaanalysis.AAlogoPlot.multi_logo
        • aaanalysis.AAlogoPlot.single_logo
      • aaanalysis.AAWindowSampler
      • aaanalysis.comp_seq_sim
      • aaanalysis.filter_seq
      • aaanalysis.scan_motif
    • Feature Engineering
    • PU Learning
    • Explainable AI
    • Protein Design
    • Utility Functions
  • Tables
  • References
  • Release notes
AAanalysis
  • API
  • aaanalysis.AAlogoPlot
  • aaanalysis.AAlogoPlot.multi_logo
  • Edit on GitHub

aaanalysis.AAlogoPlot.multi_logo

AAlogoPlot.multi_logo(list_df_logo=None, target_p1_site=None, figsize_per_logo=(8, 3), fontsize_labels=None, list_name_data=None, name_data_pos='top', list_name_data_color='black', name_data_fontsize=None, logo_font_name='Verdana', logo_color_scheme='weblogo_protein', logo_stack_order='big_on_top', logo_width=0.96, logo_vpad=0.05, logo_vsep=0.0, start=1, tmd_color='mediumspringgreen', jmd_color='blue', fontsize_tmd_jmd=None, weight_tmd_jmd='normal', highlight_tmd_area=True, highlight_alpha=0.15, xtick_size=None, xtick_width=2.0, xtick_length=11.0)[source]

Plot multiple sequence logos stacked vertically for group comparison.

All logos share the same y-axis scale. TMD/JMD annotations are shown only on the bottom subplot to avoid repetition.

Parameters:
  • list_df_logo (list of pd.DataFrame, each shape (n_positions, n_amino_acids)) – List of logo matrices, one per group. All must have the same number of positions.

  • target_p1_site (int, optional) – If set, replaces the standard JMD/TMD x-axis with P-site notation.

  • figsize_per_logo (tuple of (int or float), default=(8, 3)) – Figure size (width, height) per subplot in inches. Total figure height is figsize_per_logo[1] * len(list_df_logo).

  • fontsize_labels (int or float, optional) – Font size for axis labels.

  • list_name_data (list of str, optional) – Dataset names, one per logo. Length must match list_df_logo.

  • name_data_pos ({'top', 'right', 'bottom', 'left'}, default='top') – Position of the name annotation on each subplot.

  • list_name_data_color (str or list of str, default='black') – Color(s) for name annotations. A single string applies to all; a list must match list_df_logo in length.

  • name_data_fontsize (int or float, optional) – Font size for name annotations.

  • logo_font_name (str, default='Verdana') – Font name for amino acid letter rendering.

  • logo_color_scheme (str, default='weblogo_protein') – Color scheme for amino acid letters (passed to logomaker).

  • logo_stack_order ({'big_on_top', 'small_on_top', 'fixed'}, default='big_on_top') – Stacking order of letters within each position column.

  • logo_width (float, default=0.96) – Relative width of each letter column (0 to 1).

  • logo_vpad (float, default=0.05) – Vertical padding between stacked letters.

  • logo_vsep (float, default=0.0) – Vertical separation between stacked letters.

  • start (int, default=1) – Residue number assigned to the first position of JMD-N.

  • tmd_color (str, default='mediumspringgreen') – Color for TMD annotations.

  • jmd_color (str, default='blue') – Color for JMD annotations.

  • fontsize_tmd_jmd (int or float, optional) – Font size for part labels. If None, auto-sized.

  • weight_tmd_jmd ({'normal', 'bold'}, default='normal') – Font weight for part labels.

  • highlight_tmd_area (bool, default=True) – If True, shades the TMD region in each subplot.

  • highlight_alpha (float, default=0.15) – Opacity of the TMD highlight.

  • xtick_size (int or float, optional) – Font size for x-tick labels (bottom subplot only).

  • xtick_width (int or float, default=2.0) – Line width of x-tick marks.

  • xtick_length (int or float, default=11.0) – Length of x-tick marks in points.

Returns:

  • fig (plt.Figure) – Figure object.

  • axes (list of plt.Axes) – One Axes per logo.

See also

  • AAlogoPlot.single_logo(): for a single-group visualization.

  • AAlogo: to compute df_logo for each group.

Examples

AAlogoPlot.multi_logo stacks multiple sequence logos vertically in one figure, one subplot per logo. All subplots share the same y-axis scale. Part annotations (JMD-N, TMD, JMD-C bar and text) are shown only on the bottom subplot.

import warnings
warnings.filterwarnings('ignore')
import aaanalysis as aa
import matplotlib.pyplot as plt

aa.plot_settings()

sf = aa.SequenceFeature()
df_seq = aa.load_dataset(name='DOM_GSEC', n=100)
labels = df_seq['label'].to_list()
df_parts = sf.get_df_parts(df_seq=df_seq, list_parts=['jmd_n', 'tmd', 'jmd_c'])

aal = aa.AAlogo(logo_type='probability')
df_logo_pos = aal.get_df_logo(df_parts=df_parts, labels=labels, label_test=1)
df_logo_neg = aal.get_df_logo(df_parts=df_parts, labels=labels, label_test=0)

aal_plot = aa.AAlogoPlot(logo_type='probability', jmd_n_len=10, jmd_c_len=10)

A list of logo DataFrames — one per subplot. All must have the same number of positions. The number of subplots equals len(list_df_logo).

# Two logos: one subplot per group
fig, axes = aal_plot.multi_logo(list_df_logo=[df_logo_pos, df_logo_neg])
print(f"n_subplots: {len(axes)}, positions per logo: {len(df_logo_pos)}")
plt.show()
n_subplots: 2, positions per logo: 43
../_images/aalogo_plot_multi_logo_1_output_3_1.png

list_name_data annotates each subplot with a label. Length must match list_df_logo. list_name_data_color sets the color — either a single string (applies to all) or a list with one color per subplot.

fig, axes = aal_plot.multi_logo(
    list_df_logo=[df_logo_pos, df_logo_neg],
    list_name_data=['Positive (label=1)', 'Negative (label=0)'],
    list_name_data_color=['tab:green', 'tab:gray'],
)
plt.show()
../_images/aalogo_plot_multi_logo_2_output_5_0.png

Controls where the label is placed on each subplot’s axes. Uses ax.transAxes coordinates, so the same position applies to every subplot.

for pos in ['top', 'right', 'left']:
    fig, axes = aal_plot.multi_logo(
        list_df_logo=[df_logo_pos, df_logo_neg],
        list_name_data=['Positive', 'Negative'],
        name_data_pos=pos,
    )
    fig.suptitle(f"name_data_pos='{pos}'", y=1.01)
    plt.show()
../_images/aalogo_plot_multi_logo_3_output_7_0.png ../_images/aalogo_plot_multi_logo_4_output_7_1.png ../_images/aalogo_plot_multi_logo_5_output_7_2.png

Sets the (width, height) of each individual subplot in inches. Total figure height = figsize_per_logo[1] * len(list_df_logo).

for h in [2, 4]:
    fig, axes = aal_plot.multi_logo(
        list_df_logo=[df_logo_pos, df_logo_neg],
        list_name_data=['Positive', 'Negative'],
        figsize_per_logo=(10, h),
    )
    print(f"figsize_per_logo height={h}: total fig height = {fig.get_size_inches()[1]:.1f} in")
    plt.show()
figsize_per_logo height=2: total fig height = 4.0 in
../_images/aalogo_plot_multi_logo_6_output_9_1.png
figsize_per_logo height=4: total fig height = 8.0 in
../_images/aalogo_plot_multi_logo_7_output_9_3.png

logo_color_scheme is passed directly to logomaker.Logo. Common options: 'weblogo_protein' (default), 'chemistry', 'hydrophobicity'.

logo_stack_order controls letter stacking within each column: 'big_on_top' (default), 'small_on_top', 'fixed'.

for scheme in ['weblogo_protein', 'chemistry']:
    fig, axes = aal_plot.multi_logo(
        list_df_logo=[df_logo_pos, df_logo_neg],
        list_name_data=['Positive', 'Negative'],
        logo_color_scheme=scheme,
    )
    fig.suptitle(f"logo_color_scheme='{scheme}'", y=1.01)
    plt.show()
../_images/aalogo_plot_multi_logo_8_output_11_0.png ../_images/aalogo_plot_multi_logo_9_output_11_1.png

highlight_tmd_area=True (default) shades the TMD region in every subplot. highlight_alpha controls the opacity of the shading (0 = invisible, 1 = opaque).

for alpha in [0.0, 0.15, 0.4]:
    fig, axes = aal_plot.multi_logo(
        list_df_logo=[df_logo_pos, df_logo_neg],
        list_name_data=['Positive', 'Negative'],
        highlight_tmd_area=alpha > 0,
        highlight_alpha=alpha if alpha > 0 else 0.15,
    )
    fig.suptitle(f"highlight_tmd_area={alpha > 0}, highlight_alpha={alpha}", y=1.01)
    plt.show()
../_images/aalogo_plot_multi_logo_10_output_13_0.png ../_images/aalogo_plot_multi_logo_11_output_13_1.png ../_images/aalogo_plot_multi_logo_12_output_13_2.png

Set the color of the TMD and JMD part bar, x-tick marks, and TMD highlight rectangle across all subplots.

fig, axes = aal_plot.multi_logo(
    list_df_logo=[df_logo_pos, df_logo_neg],
    list_name_data=['Positive', 'Negative'],
    tmd_color='darkorange',
    jmd_color='steelblue',
)
plt.show()
../_images/aalogo_plot_multi_logo_13_output_15_0.png

Sets the residue number of the first position. Shifts x-tick labels on the bottom subplot only — does not affect positions or highlight coordinates.

for start in [1, 5]:
    fig, axes = aal_plot.multi_logo(
        list_df_logo=[df_logo_pos, df_logo_neg],
        list_name_data=['Positive', 'Negative'],
        start=start,
    )
    fig.suptitle(f"start={start}", y=1.01)
    plt.show()
../_images/aalogo_plot_multi_logo_14_output_17_0.png ../_images/aalogo_plot_multi_logo_15_output_17_1.png

These control the appearance of the ‘JMD-N’, ‘TMD’, ‘JMD-C’ text labels, which are drawn only on the bottom subplot.

fig, axes = aal_plot.multi_logo(
    list_df_logo=[df_logo_pos, df_logo_neg],
    list_name_data=['Positive', 'Negative'],
    weight_tmd_jmd='bold',
    fontsize_tmd_jmd=14,
)
plt.show()
../_images/aalogo_plot_multi_logo_16_output_19_0.png

When set, replaces the standard JMD/TMD x-axis on every subplot with P-site notation (P2, P1, P1’, P2’, …). The value is the 0-based position index of the P1 cleavage site.

# P1 site at position index 10 (start of TMD in a 10+20+10 layout)
fig, axes = aal_plot.multi_logo(
    list_df_logo=[df_logo_pos, df_logo_neg],
    list_name_data=['Positive', 'Negative'],
    target_p1_site=10,
)
plt.show()
../_images/aalogo_plot_multi_logo_17_output_21_0.png

All subplots automatically share the same y-axis maximum, computed from the maximum per-position sum across all logos. This makes group comparisons visually fair.

fig, axes = aal_plot.multi_logo(
    list_df_logo=[df_logo_pos, df_logo_neg],
    list_name_data=['Positive', 'Negative'],
)
ylims = [ax.get_ylim() for ax in axes]
print(f"y-axis limits per subplot: {ylims}")
print(f"All equal: {len(set(ylims)) == 1}")
plt.show()
y-axis limits per subplot: [(np.float64(0.0), np.float64(100.00000000000003)), (np.float64(0.0), np.float64(100.00000000000003))]
All equal: True
../_images/aalogo_plot_multi_logo_18_output_23_1.png
Previous Next

© Copyright 2026, Stephan Breimann.