RNApysoforms.make_plot
- RNApysoforms.make_plot(traces: List[Trace], subplot_titles: List[str] = ['Transcript Structure'], horizontal_spacing: float = 0.02, vertical_spacing: float = 0.02, showlegend: bool = True, height: int = 900, width: int = 1800, template: str = 'plotly_white', boxgroupgap: float = 0.8, boxgap: float = 0.2, vert_grid_transcript_structure_plot: bool = True, horz_grid_transcript_structure_plot: bool = True, vert_grid_expression_plot: bool = True, horz_grid_expression_plot: bool = True, legend_font_size: int = 12, xaxis_font_size: int = 12, yaxis_font_size: int = 12, subplot_title_font_size: int = 16, legend_title_font_size: int = 14, hover_font_size: int = 12, hovermode: str = 'closest', column_widths: list | None = None) Figure[source]
Creates a multi-panel Plotly figure combining transcript structure plots and expression data plots.
This function constructs a Plotly figure with multiple subplots arranged horizontally. It accepts a list of Plotly traces representing different data types (e.g., transcript structures, expression data) and organizes them into subplots. The function customizes the layout, axes, and appearance of each subplot based on the provided parameters, allowing for flexible visualization of genomic data alongside expression metrics.
Expected Structure of `traces`: - The traces list should contain multiple sublists, each representing traces for a subplot. - The last element in traces must be a dictionary (y_dict) mapping transcript identifiers to y-axis positions.
- Parameters:
traces (List[List[go.Trace]] or List[List[dict]]) – A list where each element is a list of Plotly traces (either go.Trace objects or dictionaries for transcript structures). The last element must be a dictionary mapping transcript identifiers to y-axis positions.
subplot_titles (List[str], optional) – A list of titles for each subplot. Default is [“Transcript Structure”].
horizontal_spacing (float, optional) – Horizontal spacing between subplots as a fraction of the average subplot width. Default is 0.02.
vertical_spacing (float, optional) – Vertical spacing between subplots as a fraction of the average subplot height. Default is 0.02.
showlegend (bool, optional) – Whether to display the legend. Default is True.
height (int, optional) – The height of the figure in pixels. Default is 800.
width (int, optional) – The width of the figure in pixels. Default is 1800.
template (str, optional) – The Plotly template to use for styling. Default is “plotly_white”.
boxgroupgap (float, optional) – Gap between grouped boxes in box or violin plots. Default is 0.8.
boxgap (float, optional) – Gap between individual boxes in box or violin plots. Default is 0.2.
vert_grid_transcript_structure_plot (bool, optional) – Whether to show vertical grid lines in transcript structure plots. Default is True.
horz_grid_transcript_structure_plot (bool, optional) – Whether to show horizontal grid lines in transcript structure plots. Default is True.
vert_grid_expression_plot (bool, optional) – Whether to show vertical grid lines in expression plots. Default is True.
horz_grid_expression_plot (bool, optional) – Whether to show horizontal grid lines in expression plots. Default is True.
legend_font_size (int, optional) – Font size for legend text. Default is 12.
xaxis_font_size (int, optional) – Font size for x-axis labels. Default is 12.
yaxis_font_size (int, optional) – Font size for y-axis labels. Default is 12.
subplot_title_font_size (int, optional) – Font size for subplot titles. Default is 16.
legend_title_font_size (int, optional) – Font size for the legend title. Default is 14.
hover_font_size (int, optional) – Font size for hover text labels. Default is 12.
hovermode (str, optional) – Hover mode for the figure. Options include “closest”, “x”, “y”, “x unified”, “y unified”, etc. Default is “closest”.
columns_widths (list, optional) – A list of floats containing the same number of items as the number of subplots you are trying to generate. For a figure with three subplots you could pass [0.4, 0.3, 0.3] to make the first subplot take up 40% of the horizontal space and the second and third subplot each take 30% of the horizontal space. By default it is set to None which will make the subplots have proportional sizes.
- Returns:
A Plotly Figure object containing the assembled subplots with customized layout and styling.
- Return type:
go.Figure
- Raises:
ValueError – If traces does not contain at least one set of traces and a y_dict mapping.
Examples
Create a figure with transcript structure and expression data:
>>> import plotly.graph_objects as go >>> from RNApysoforms import make_plot >>> fig = make_plot( ... traces=traces, ... subplot_titles=["Transcript Structure", "Expression Levels"], ... height=600, ... width=1200 ... ) >>> fig.show()
Notes
The function expects the last element of traces to be a dictionary (y_dict) mapping transcript identifiers to y-axis positions.
- Traces are classified into transcript structure traces or expression data traces based on their content:
Transcript traces are expected to be dictionaries (usually shapes or annotations).
Expression traces are expected to be Plotly trace objects with a ‘type’ attribute (e.g., go.Box, go.Violin).
The function dynamically assigns traces to subplots and customizes axes and layout based on the type of data.
The y-axis is shared across subplots to align transcript structures with their corresponding expression data.
Hover settings can be customized using the hovermode parameter.