From c8b98dccec626077796843c2702001e1ef5a8522 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 26 Nov 2016 16:52:46 +0300 Subject: [PATCH] Split ploting in 2 --- notes_tools/tools/marks_plottings.py | 53 ++++++++++++++++++++++++++++ notes_tools/tools/plottings.py | 4 +-- 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 notes_tools/tools/marks_plottings.py diff --git a/notes_tools/tools/marks_plottings.py b/notes_tools/tools/marks_plottings.py new file mode 100644 index 0000000..70930be --- /dev/null +++ b/notes_tools/tools/marks_plottings.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from .plottings import radar_graph +import pandas as pd +import numpy as np + +def comp_radar(df, optimum = None): + """ Plot the radar graph concerning "Competence" column of the df + + :param df: DataFrame with "Competence", "Normalized" + :returns: exes with radar plot + + """ + comp_pt = pd.pivot_table(df, + index = ["Competence"], + values = ["Normalized"], + aggfunc=np.mean, + ) + labels = list(comp_pt.index) + values = [i[0] for i in comp_pt.values] + if optimum is None: + optimum = [1]*len(values) + fig, ax = radar_graph(labels, values, optimum) + return fig, ax + +def marks_hist(df): + """ Return axe for the histogramme of the dataframe + + :param df: Dataframe with "Mark" and "Bareme" columns. If it has "Nom" column, it is use in title. + """ + bareme = df["Bareme"].max() + bins = bareme*2 + + ax = df["Mark"].hist(bins = bins, range=(0,bareme)) + + try: + nom = df["Nom"].unique() + except KeyError: + title="Histogramme" + else: + title="Histogramme pour {}".format(" ".join(nom)) + + ax.set_title(title) + + return ax + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/notes_tools/tools/plottings.py b/notes_tools/tools/plottings.py index b1dc342..6f61ac5 100644 --- a/notes_tools/tools/plottings.py +++ b/notes_tools/tools/plottings.py @@ -7,6 +7,7 @@ from matplotlib.path import Path from matplotlib.spines import Spine from matplotlib.projections.polar import PolarAxes from matplotlib.projections import register_projection +plt.style.use('ggplot') def _radar_factory(num_vars): theta = 2*np.pi * np.linspace(0, 1-1./num_vars, num_vars) @@ -69,9 +70,6 @@ def radar_graph(labels = [], values = [], optimum = []): ax.plot(theta, optimum, color='r') ax.set_varlabels(labels) return fig, ax - #plt.show() - #plt.savefig("radar.png", dpi=100) - # -----------------------------