plot_volcano#
- DE.plot_volcano(cell_type, filename=None, /, *, ax=None, figure_kwargs=None, x_column='logFC', y_column='p', significance_column='FDR', threshold=0.05, genes_to_label=10, label_kwargs=None, upregulated_size=6, downregulated_size=6, non_significant_size=4, upregulated_color='#FC4E07', downregulated_color='#00AFBB', non_significant_color='lightgray', upregulated_scatter_kwargs=None, downregulated_scatter_kwargs=None, non_significant_scatter_kwargs=None, legend=True, legend_kwargs=None, title=None, title_kwargs=None, xlabel='$log_2(FC)$', xlabel_kwargs=None, ylabel=Ellipsis, ylabel_kwargs=None, despine=True, savefig_kwargs=None)[source]#
Generate a volcano plot of DE hits.
Plots negative log p-values (or another y_column) on the y-axis against log fold changes (or another x_column) on the x-axis. Upregulated, downregulated and non-significant genes are plotted in three different colors based on significance_column.
- Parameters:
cell_type: str
the cell type to generate the volcano plot for
filename: str | Path | None
the file to save to. If None, generate the plot but do not save it, which allows it to be shown interactively or modified further before saving.
ax: 'Axes' | None
the Matplotlib axes to save the plot onto; if None, create a new figure with Matpotlib’s constrained layout and plot onto it
figure_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
plt.figure()when ax is None, such as:figsize: a two-element sequence of the width and height of the figure in inches. Defaults to Matplotlib’s default of [6.4, 4.8].
layout: the layout mechanism used by Matplotlib to avoid overlapping plot elements. Defaults to ‘constrained’, instead of Matplotlib’s default of None.
x_column: str
the name of a numeric column of self.table to plot on the x-axis
y_column: str
the name of a numeric column of self.table to plot the negative log of on the y-axis
significance_column: str
the name of a numeric column of self.table to determine significance from
threshold: int | float
the significance threshold corresponding to significance_column
genes_to_label: int | str | Iterable[str] | None
an integer number of top DE genes (according to y_column) to label, a name or sequence of names of genes to label, or None to not add labels. If an integer, only significant DE genes (according to significance_column) will be labeled, even if genes_to_label is larger than the number of DE genes.
label_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
textalloc.allocate()when adding gene labels to control the textproperties, such as:textcolor/textsize: the text color and size
x_scatter/y_scatter: the x/y coordinates of points in the scatter plot, to repel labels away from. Defaults to all points in the plot.
min_distance/max_distance: the minimum and maximum distances from each point to its label, as a proportion of the width of the x-axis. Defaults to 0 and 0.02, instead of textalloc’s defaults of 0.015 and 0.2
draw_lines: whether to draw lines between each label and its corresponding point. Defaults to False, instead of textalloc’s default of True.
See here for the full list of possible arguments. Can only be specified when genes_to_label is non-zero.
upregulated_size: int | float
the size of each upregulated gene’s point
downregulated_size: int | float
the size of each downregulated gene’s point
non_significant_size: int | float
the size of each non-significant gene’s point
upregulated_color: Color
the color of each upregulated gene’s point. Can be any valid Matplotlib color, like a hex string (e.g. ‘#FF0000’), a named color (e.g. ‘red’), a 3- or 4-element RGB/RGBA tuple of integers 0-255 or floats 0-1, or a single float 0-1 for grayscale.
downregulated_color: Color
the color of each downregulated gene’s point. Can be any valid Matplotlib color, like a hex string (e.g. ‘#FF0000’), a named color (e.g. ‘red’), a 3- or 4-element RGB/RGBA tuple of integers 0-255 or floats 0-1, or a single float 0-1 for grayscale.
non_significant_color: Color
the color of each non-significant gene’s point. Can be any valid Matplotlib color, like a hex string (e.g. ‘#FF0000’), a named color (e.g. ‘red’), a 3- or 4-element RGB/RGBA tuple of integers 0-255 or floats 0-1, or a single float 0-1 for grayscale.
upregulated_scatter_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.scatter()for upregulated genes, such as:rasterized: whether to convert the scatter plot points to a raster (bitmap) image when saving to a vector format like PDF. Defaults to True, instead of Matplotlib’s default of False.
marker: the shape to use for plotting each gene
alpha: the transparency of each point
linewidths and edgecolors: the width and color of the borders around each marker. These are absent by default (linewidths=0, edgecolors=(0, 0, 0, 0)), unlike Matplotlib’s default. Both arguments can be either single values or sequences.
zorder: the order in which the genes are plotted, with higher values appearing on top of lower ones.
Specifying s or c/color/norm/ vmin/vmax will raise an error, since these arguments conflict with the upregulated_size and upregulated_color arguments, respectively.
downregulated_scatter_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.scatter()for downregulated genes; see the documentation of the upregulated_scatter_kwargs argument for detailsnon_significant_scatter_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.scatter()for non-significant genes; see the documentation of the upregulated_scatter_kwargs argument for detailslegend: bool
whether to add a legend showing the marker style for upregulated, downregulated, and non-significant points
legend_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.legend()to modify the legend, such as:loc, bbox_to_anchor, and bbox_transform to set its location.
prop, fontsize, and labelcolor to set its font properties
facecolor and framealpha to set its background color and transparency
frameon=True or edgecolor to add or color its border. frameon defaults to False, instead of Matplotlib’s default of True.
title to add a legend title
Can only be specified when legend=True.
title: str | None
the title of the plot, or None to not add a title
title_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.set_title()to control text properties, such as color and size. Can only be specified when title is not None.xlabel: str | None
the x-axis label, or None to not label the x-axis
xlabel_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.set_xlabel()to control text properties, such as color and size. Can only be specified when xlabel is not None.ylabel: str | None
the y-axis label, or None to not label the y-axis. Defaults to f’$-log_{{10}}({y_column})$’.
ylabel_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
ax.set_ylabel()to control text properties, such as color and size. Can only be specified when ylabel is not None.despine: bool
whether to remove the top and right spines (borders of the plot area) from the volcano plot
savefig_kwargs: dict[str, Any] | None
a dictionary of keyword arguments to be passed to
plt.savefig(), such as:dpi: defaults to 300 instead of Matplotlib’s default of 150
bbox_inches: the bounding box of the portion of the figure to save; defaults to ‘tight’ (crop out any blank borders) instead of Matplotlib’s default of None (save the entire figure)
pad_inches: the number of inches of padding to add on each of the four sides of the figure when saving. Defaults to ‘layout’ (use the padding from the constrained layout engine), instead of Matplotlib’s default of 0.1.
transparent: whether to save with a transparent background; defaults to True if saving to a PDF (i.e. when PNG=False) and False if saving to a PNG, instead of Matplotlib’s default of always being False.
Can only be specified when filename is specified.
- Return type:
None