Plotting
Functions:
|
Plot a collection of intervals, one plot per chromosome. |
|
Convert any matplotlib color identifier into a UCSC itemRgb color string. |
- plot_intervals(df, levels=None, labels=None, colors=None, xlim=None, show_coords=False, figsize=(10, 2))[source]
Plot a collection of intervals, one plot per chromosome.
- Parameters:
df (pandas.DataFrame) – A collection of intervals.
levels (iterable or None) – The level of each interval, i.e. the y-coordinate at which the interval must be plotted. If None, it will be determined automatically.
labels (str or iterable or None) – The label of each interval.
colors (str or iterable or None.) – The color of each interval.
xlim ((float, float) or None) – The x-span of the plot.
show_coords (bool) – If True, plot x-ticks.
figsize ((float, float) or None.) – The size of the figure. If None, plot within the current figure.
- to_ucsc_colorstring(color: str | tuple) str [source]
Convert any matplotlib color identifier into a UCSC itemRgb color string.
- Parameters:
color (str or tuple) – Any valid matplotlib color representation (e.g. ‘red’, ‘tomato’, ‘#ff0000’, ‘#ff00’, “#ff000055”, (1, 0, 0), (1, 0, 0, 0.5))
- Returns:
A UCSC itemRgb colorstring of the form “r,g,b” where r, g, and b are integers between 0 and 255, inclusive.
- Return type:
str
Notes
The alpha (opacity) channel is ignored if represented in the input.
Null values are converted to “0”, which is shorthand for “0,0,0” (black). Note that BED9+ files with uninformative itemRgb values should use “0” as the itemRgb value on every data line.
Examples
>>> to_ucsc_colorstring("red") '255,0,0' >>> to_ucsc_colorstring("tomato") '255,99,71' >>> df["itemRgb"] = df["color"].apply(to_ucsc_colorstring) >>> df chrom start end color itemRgb chr1 0 10 red 255,0,0 chr1 10 20 blue 0,0,255 chr2 0 10 green 0,128,0 chr2 10 20 None 0