[change] extracted plotting and started new module for plotting; improved docstring quality
This commit is contained in:
@@ -363,6 +363,18 @@ class ProbabilityDensityFunction(object):
|
||||
return m
|
||||
|
||||
def quantile_distance(self, prob_value):
|
||||
"""
|
||||
takes a probability value and and returns the distance
|
||||
between two complementary quantiles
|
||||
|
||||
.. math::
|
||||
|
||||
QA_\alpha = Q(1 - \alpha) - Q(\alpha)
|
||||
|
||||
:param value: probability value :math:\alpha
|
||||
:type value: float
|
||||
:return: quantile distance
|
||||
"""
|
||||
if 0 >= prob_value or prob_value >= 0.5:
|
||||
raise ValueError('Value out of range.')
|
||||
ql = self.quantile(prob_value)
|
||||
@@ -370,7 +382,20 @@ class ProbabilityDensityFunction(object):
|
||||
return qu - ql
|
||||
|
||||
|
||||
def qtile_dist_quot(self,x):
|
||||
def quantile_dist_frac(self, x):
|
||||
"""
|
||||
takes a probability value and returns the fraction of two
|
||||
corresponding quantile distances (
|
||||
:func:`pylot.core.util.pdf.ProbabilityDensityFunction
|
||||
#quantile_distance`)
|
||||
|
||||
.. math::
|
||||
|
||||
Q\Theta_\alpha = \frac{QA(0.5 - \alpha)}{QA(\alpha)}
|
||||
|
||||
:param value: probability value :math:\alpha
|
||||
:return: quantile distance fraction
|
||||
"""
|
||||
if x <= 0 or x >= 0.25:
|
||||
raise ValueError('Value out of range.')
|
||||
return self.quantile_distance(0.5-x)/self.quantile_distance(x)
|
||||
|
||||
57
pylot/core/util/plotting.py
Normal file
57
pylot/core/util/plotting.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def create_bin_list(l_boundary, u_boundary, nbins=100):
|
||||
"""
|
||||
takes two boundaries and a number of bins and creates a list of bins for
|
||||
histogram plotting
|
||||
:param l_boundary: Any number.
|
||||
:type l_boundary: float
|
||||
:param u_boundary: Any number that is greater than l_boundary.
|
||||
:type u_boundary: float
|
||||
:param nbins: Any positive integer.
|
||||
:type nbins: int
|
||||
:return: A list of equidistant bins.
|
||||
"""
|
||||
if u_boundary <= l_boundary:
|
||||
raise ValueError('Upper boundary must be greather than lower!')
|
||||
elif nbins <= 0:
|
||||
raise ValueError('Number of bins is not valid.')
|
||||
binlist = []
|
||||
for i in range(nbins):
|
||||
binlist.append(l_boundary + i * (u_boundary - l_boundary) / nbins)
|
||||
return binlist
|
||||
|
||||
|
||||
def histplot(array, binlist, xlab='Values',
|
||||
ylab='Frequency', title=None, fnout=None):
|
||||
"""
|
||||
function to quickly show some distribution of data. Takes array like data,
|
||||
and a list of bins. Editing detail and inserting a legend is not possible.
|
||||
:param array: List of values.
|
||||
:type array: Array like
|
||||
:param binlist: List of bins.
|
||||
:type binlist: list
|
||||
:param xlab: A label for the x-axes.
|
||||
:type xlab: str
|
||||
:param ylab: A label for the y-axes.
|
||||
:type ylab: str
|
||||
:param title: A title for the Plot.
|
||||
:type title: str
|
||||
:param fnout: A path to save the plot instead of showing.
|
||||
Has to contain filename and type. Like: 'path/to/file.png'
|
||||
:type fnout. str
|
||||
:return: -
|
||||
"""
|
||||
|
||||
plt.hist(array, bins=binlist)
|
||||
plt.xlabel(xlab)
|
||||
plt.ylabel(ylab)
|
||||
if title:
|
||||
plt.title(title)
|
||||
if fnout:
|
||||
plt.savefig(fnout)
|
||||
else:
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user