Skip to content
Snippets Groups Projects
Commit 14de21d2 authored by Blaise Li's avatar Blaise Li
Browse files

Forward arguments to violin plot.

parent 6b3bb11b
No related branches found
No related tags found
No related merge requests found
......@@ -1089,6 +1089,11 @@ def to_long_form(usage_table, ylabel, others=None):
See https://pandas.pydata.org/docs/user_guide/10min.html#stack
and https://seaborn.pydata.org/generated/seaborn.violinplot.html
*y_label* is the column header you want to set for the usage values.
*others* should be a list of extra information you want to extract
from the index (which is expected to be a pandas MultiIndex).
"""
col_nb_levels = usage_table.columns.nlevels
row_nb_levels = usage_table.index.nlevels
......@@ -1141,7 +1146,9 @@ def format_codon_labels(codons):
for (x, y, codon) in map(attrgetter("_x", "_y", "_text"), codons)]
def violin_usage(usage_table, variable, ylabel, hue="aa", axis=None):
def violin_usage(
usage_table, variable, ylabel,
hue="aa", axis=None, **violin_kwargs):
"""
Plot violin plots of codon usage biases.
......@@ -1157,15 +1164,20 @@ def violin_usage(usage_table, variable, ylabel, hue="aa", axis=None):
palette = aa2colour
else:
palette = None
# if variable == "aa":
# order = list(columns_by_aa.keys())
# elif variable == "codon":
# order = [codon for (_, codon) in concat(columns_by_aa.values())]
# else:
# raise ValueError("variable can only be 'aa' or 'codon'.\n")
sns.violinplot(x=variable, y=ylabel, order=variable2order(variable),
hue=hue, palette=palette, dodge=False,
data=long_form, ax=axis, orient="v", scale="count")
if hue in {"aa", "codon"}:
dodge = False
else:
dodge = True
kwargs = {
"x": variable, "y": ylabel, "order": variable2order(variable),
"hue": hue, "palette": palette, "dodge": dodge,
"data": long_form, "ax": axis, "orient": "v", "scale": "count"}
kwargs.update(violin_kwargs)
sns.violinplot(**kwargs)
# sns.violinplot(x=variable, y=ylabel, order=variable2order(variable),
# hue=hue, palette=palette, dodge=dodge,
# data=long_form, ax=axis, orient="v", scale="count",
# **violin_kwargs)
if do_legend:
plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0)
if variable == "codon":
......@@ -1176,7 +1188,9 @@ def violin_usage(usage_table, variable, ylabel, hue="aa", axis=None):
return axis
def violin_usage_vertical(usage_table, variable, ylabel, hue="aa", axis=None):
def violin_usage_vertical(
usage_table, variable, ylabel,
hue="aa", axis=None, **violin_kwargs):
"""
Plot vertically stacked violin plots of codon usage biases.
......@@ -1189,16 +1203,22 @@ def violin_usage_vertical(usage_table, variable, ylabel, hue="aa", axis=None):
palette = aa2colour
else:
palette = None
# if variable == "aa":
# order = list(columns_by_aa.keys())
# elif variable == "codon":
# order = [codon for (_, codon) in concat(columns_by_aa.values())]
# else:
# raise ValueError("variable can only be 'aa' or 'codon'.\n")
sns.violinplot(
y=variable, x=ylabel, order=variable2order(variable),
hue=hue, palette=palette, dodge=False,
data=long_form, ax=axis, orient="h", scale="count")
if hue in {"aa", "codon"}:
dodge = False
else:
dodge = True
kwargs = {
"y": variable, "x": ylabel,
"order": variable2order(variable),
"hue": hue, "palette": palette, "dodge": dodge,
"data": long_form, "ax": axis, "orient": "h", "scale": "count"}
kwargs.update(violin_kwargs)
sns.violinplot(**kwargs)
# sns.violinplot(
# y=variable, x=ylabel, order=variable2order(variable),
# hue=hue, palette=palette, dodge=dodge,
# data=long_form, ax=axis, orient="h", scale="count",
# **violin_kwargs)
if variable == "codon":
ticklabels = format_codon_labels(axis.get_yticklabels())
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment