Skip to content
Snippets Groups Projects
Commit 95638923 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Use OO-style

parent 032dea79
No related branches found
No related tags found
No related merge requests found
...@@ -62,11 +62,11 @@ def fig_hist(xlabel, x, label): ...@@ -62,11 +62,11 @@ def fig_hist(xlabel, x, label):
"""Creates a complete figure with histogram. x and label can also be """Creates a complete figure with histogram. x and label can also be
sequences.""" sequences."""
plt.figure() fig, ax = plt.subplots()
plt.hist(x, bins = "auto", histtype = "step", label = label) ax.hist(x, bins = "auto", histtype = "step", label = label)
plt.xlabel(xlabel) ax.set_xlabel(xlabel)
plt.ylabel("number of occurrences") ax.set_ylabel("number of occurrences")
if label is not None: plt.legend() if label is not None: ax.legend()
def fig_distr_funct(xlabel, x, label = None): def fig_distr_funct(xlabel, x, label = None):
"""Creates a complete figure with distribution function. x must be a """Creates a complete figure with distribution function. x must be a
...@@ -74,18 +74,18 @@ def fig_distr_funct(xlabel, x, label = None): ...@@ -74,18 +74,18 @@ def fig_distr_funct(xlabel, x, label = None):
""" """
plt.figure() fig, ax = plt.subplots()
print(xlabel + ":") print(xlabel + ":")
label_None = label is None label_None = label is None
if label_None: label = itertools.repeat(None) if label_None: label = itertools.repeat(None)
for xi, li in zip(x, label): for xi, li in zip(x, label):
plot_distr_funct(xi, label = li) plot_distr_funct(xi, li, ax)
plt.xlabel(xlabel) ax.set_xlabel(xlabel)
plt.ylabel("distribution function") ax.set_ylabel("distribution function")
if not label_None: plt.legend() if not label_None: ax.legend()
def plot_all(dict_list, label = None): def plot_all(dict_list, label = None):
"""dict_list: list of dictionaries. label: list of labels, one label """dict_list: list of dictionaries. label: list of labels, one label
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment