From 1c359179094b9881717e338b9dfa96d84e761724 Mon Sep 17 00:00:00 2001 From: markus Date: Tue, 19 Jan 2021 14:20:52 +0100 Subject: [PATCH] document logscale_hist --- cara/montecarlo.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cara/montecarlo.py b/cara/montecarlo.py index 8725c107..35434799 100644 --- a/cara/montecarlo.py +++ b/cara/montecarlo.py @@ -1,6 +1,6 @@ import numpy as np import scipy.stats as sct -from typing import Optional +from typing import Optional, Iterable import matplotlib.pyplot as plt @@ -53,9 +53,15 @@ def generate_qr_values(samples: int, expiratory_activity: int, masked: bool, qid return qr_func(viral_loads, emissions, diameters, mask_efficiency, qid) -def logscale_hist(x, bins): - hist, bins = np.histogram(x, bins=bins) - logscale_bins = np.logspace(np.log10(bins[0]), np.log10(bins[-1]), len(bins)) - plt.hist(x, bins=logscale_bins) - plt.xscale('log') - plt.show() +def logscale_hist(x: Iterable, bins: int) -> None: + """ + Plots the data of x as a log-scale histogram + :param x: An array containing the data to be plotted + :param bins: The number of bins to be used in the histogram (number of bars) + :return: Nothing + """ + hist, bins = np.histogram(x, bins=bins) + logscale_bins = np.logspace(np.log10(bins[0]), np.log10(bins[-1]), len(bins)) + plt.hist(x, bins=logscale_bins) + plt.xscale('log') + plt.show()