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

Move functions out of repository

Move functions `plot_distr_funct`, `fig_hist` and `fig_distr_funct` to
module `jumble_matplotlib`, out of this repository, because they are
of more general interest.
parent 914e26e8
No related branches found
No related tags found
No related merge requests found
......@@ -2,23 +2,8 @@
import shapefile
import numpy as np
import matplotlib.pyplot as plt
import itertools
from os import path
def plot_distr_funct(x, label = None, ax = None):
"""Sort and plot distribution function. x should be a Numpy array."""
x_sorted = np.sort(x)
nx = np.size(x)
if nx != 0:
if ax is None: fig, ax = plt.subplots()
ax.plot(x_sorted, (1 + np.arange(nx)) / nx, label = label)
print("minimum value:", x_sorted[0])
print("maximum value:", x_sorted[- 1])
print("number of values:", nx, "\n")
import jumble_matplotlib
def read(dirname):
"""Read the three dbf files in dirname and return speed, radius and
......@@ -58,69 +43,47 @@ def read(dirname):
"amp_outer": np.abs(np.array(amp_outer)),
"amp_speed": np.abs(np.array(amp_speed))}
def fig_hist(xlabel, x, label):
"""Creates a complete figure with histogram. x and label can also be
sequences."""
fig, ax = plt.subplots()
ax.hist(x, bins = "auto", histtype = "step", label = label)
ax.set_xlabel(xlabel)
ax.set_ylabel("number of occurrences")
if label is not None: ax.legend()
def fig_distr_funct(xlabel, x, label = None):
"""Creates a complete figure with distribution function. x must be a
sequence of Numpy arrays and label None or a sequence of strings.
"""
fig, ax = plt.subplots()
print(xlabel + ":")
label_None = label is None
if label_None: label = itertools.repeat(None)
for xi, li in zip(x, label):
plot_distr_funct(xi, li, ax)
ax.set_xlabel(xlabel)
ax.set_ylabel("distribution function")
if not label_None: ax.legend()
def plot_all(dict_list, label = None):
"""dict_list: list of dictionaries. label: list of labels, one label
for each dictionary.
"""
fig_hist("speed, in m s-1", [d["speed"] for d in dict_list], label)
fig_distr_funct("speed, when positive, in m s-1",
[d["speed"][d["speed"] >= 0] for d in dict_list], label)
fig_distr_funct("speed, when negative, in m s-1",
[- d["speed"][d["speed"] < 0] for d in dict_list], label)
jumble_matplotlib.fig_hist("speed, in m s-1",
[d["speed"] for d in dict_list], label)
jumble_matplotlib.fig_distr_funct(
"speed, when positive, in m s-1",
[d["speed"][d["speed"] >= 0] for d in dict_list], label)
jumble_matplotlib.fig_distr_funct(
"speed, when negative, in m s-1",
[- d["speed"][d["speed"] < 0] for d in dict_list], label)
fig_hist("equivalent radius of outermost contour, in km",
[d["rad_outer"] for d in dict_list], label)
fig_distr_funct("equivalent radius of outermost contour, in km",
[d["rad_outer"] for d in dict_list], label)
fig_hist("equivalent radius of max-speed contour, in km",
[d["rad_speed"] for d in dict_list], label)
fig_distr_funct("equivalent radius of max-speed contour, in km",
[d["rad_speed"] for d in dict_list], label)
fig_hist("amplitude of outermost contour, in m",
jumble_matplotlib.fig_hist(
"equivalent radius of outermost contour, in km",
[d["rad_outer"] for d in dict_list], label)
jumble_matplotlib.fig_distr_funct(
"equivalent radius of outermost contour, in km",
[d["rad_outer"] for d in dict_list], label)
jumble_matplotlib.fig_hist("equivalent radius of max-speed contour, in km",
[d["rad_speed"] for d in dict_list], label)
jumble_matplotlib.fig_distr_funct(
"equivalent radius of max-speed contour, in km",
[d["rad_speed"] for d in dict_list], label)
jumble_matplotlib.fig_hist("amplitude of outermost contour, in m",
[d["amp_outer"] for d in dict_list], label)
fig_distr_funct("amplitude of outermost contour, in m",
jumble_matplotlib.fig_distr_funct("amplitude of outermost contour, in m",
[d["amp_outer"] for d in dict_list], label)
fig_hist("amplitude of max-speed contour, in m",
jumble_matplotlib.fig_hist("amplitude of max-speed contour, in m",
[d["amp_speed"] for d in dict_list], label)
fig_distr_funct("amplitude of max-speed contour, in m",
jumble_matplotlib.fig_distr_funct("amplitude of max-speed contour, in m",
[d["amp_speed"] for d in dict_list], label)
if __name__ == "__main__":
import sys
import matplotlib.pyplot as plt
if len(sys.argv) != 2:
sys.exit("Required argument: directory containing collection of "
......
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