From c16f1fb2e1c7576083b6fb879ad334623755bbef Mon Sep 17 00:00:00 2001 From: bay9355 <mia.le@studium.uni-hamburg.de> Date: Mon, 7 Aug 2023 00:26:14 +0200 Subject: [PATCH] added violin plot function --- cami_src/utils/plots.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cami_src/utils/plots.py diff --git a/cami_src/utils/plots.py b/cami_src/utils/plots.py new file mode 100644 index 0000000..0139bba --- /dev/null +++ b/cami_src/utils/plots.py @@ -0,0 +1,23 @@ +import matplotlib.pyplot as plt + +def make_violinplot(value_dct, colors, color_groups, title, ylabel, ax): + # Create a plot + groups = list(value_dct.keys()) + violins = ax[0].violinplot(list(value_dct.values()), showmeans=True, showextrema=True) + + for violinpart in list(violins.keys())[2:]: + violins[violinpart].set_color('k') + + for violin, group in zip(violins['bodies'], groups): + for i, color_group in enumerate(color_groups): + if group in color_group: + violin.set_facecolor(colors[i]) + break + # Add title + ax.set_title(title, wrap=True, fontsize=14) + + ax.set_xticks(list(range(1, len(value_dct) + 1))) + ax.set_xticklabels(value_dct.keys(), wrap=True) + ax.tick_params(axis='x', labelsize=11) + ax.set_ylabel(ylabel, wrap=True, fontsize=14) + return ax \ No newline at end of file -- GitLab