Skip to content

Commit

Permalink
【Add】 add title
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhenbin24 committed Dec 14, 2023
1 parent 96b20db commit 822fba1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions stereo/plots/plot_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ def violin(
ax: Optional[Axes] = None,
order: Optional[Iterable[str]] = None,
use_raw: Optional[bool] = False,
palette: Optional[str] = None
palette: Optional[str] = None,
title: Optional[str, Sequence[str]] = None,
):
"""
Violin plot to show index distribution of quality control.
Expand All @@ -588,6 +589,7 @@ def violin(
:param ax: a matplotlib axes object. only works if plotting a single component.
:param order: Order in which to show the categories.
:param use_raw: Whether to use raw attribute of data. Defaults to True if .raw is present.
:param title: the title.
:param palette: color theme.
For more color theme selection reference: https://seaborn.pydata.org/tutorial/color_palettes.html
:param out_path: the path to save the figure.
Expand All @@ -610,7 +612,8 @@ def violin(
ax=ax,
order=order,
use_raw=use_raw,
palette=palette
palette=palette,
title=title
)

@reorganize_coordinate
Expand Down
12 changes: 11 additions & 1 deletion stereo/plots/violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def violin_distribution(
ax: Optional[Axes] = None,
order: Optional[Iterable[str]] = None,
use_raw: Optional[bool] = False,
palette: Optional[str] = None
palette: Optional[str] = None,
title: Optional[str] = None
): # Violin Statistics Chart
"""
violin plot showing quality control index distribution
Expand All @@ -226,6 +227,7 @@ def violin_distribution(
:param order: Order in which to show the categories.
:param use_raw: Whether to use raw attribute of adata. Defaults to True if .raw is present.
:param palette: color theme.
:param title: the title.
:return: None
"""
Expand Down Expand Up @@ -261,6 +263,9 @@ def violin_distribution(
if not isinstance(obs_df.iloc[0][index_ys], float):
obs_df[index_ys] = pd.to_numeric(obs_df[index_ys], errors='coerce')

if title and not isinstance(title, list):
title = [title]

if multi_panel and group_by is None and len(ys) == 1:
y = ys[0]
g = sns.catplot(
Expand Down Expand Up @@ -291,6 +296,9 @@ def violin_distribution(
if log:
g.set(yscale='log')
g.set_titles(col_template='{col_name}').set_xlabels('')
if title:
for ax in g.axes[0]:
ax.set_title(title.pop(0) if title else '')
if rotation_angle is not None:
for ax in g.axes[0]:
ax.tick_params(axis='x', labelrotation=rotation_angle)
Expand Down Expand Up @@ -322,6 +330,8 @@ def violin_distribution(
ax.set_yscale('log')
if rotation_angle is not None:
ax.tick_params(axis='x', labelrotation=rotation_angle)
if title:
ax.set_title(title.pop(0) if title else '')
pl.show()


Expand Down

0 comments on commit 822fba1

Please sign in to comment.