Skip to content

utils.draw.plot_hist

Function ยท Source

mdnc.utils.draw.plot_hist(
    gen, normalized=False, cumulative=False,
    xlabel='Value', ylabel='Number of samples', x_log=False, y_log=False,
    figure_size=(6, 5.5), legend_loc=None, legend_col=None,
    fig=None, ax=None
)

Plot a histogram for multiple distributions. Each distribution is given by a 1D data sample array.

Arguments

Requries

Argument Type Description
gen object A generator callable object (function), each yield returns a sample. It allows users to provide an extra kwargs dict for each iteration (see Examples). For each iteration, it returns a 1D data.
normalized bool A flag. Whether to use normalization for each group when drawing the histogram.
xlabel str The x axis label.
ylabel str The y axis label.
x_log bool A flag. Whether to convert the x axis into the logarithmic format.
y_log bool A flag. Whether to convert the y axis into the logarithmic format.
figure_size (float, float) A tuple with two values representing the (width, height) of the output figure. The unit is inch.
legend_loc str or
int or
(float, float)
The localtion of the legend, see matplotlib.pyplot.legend to view details. (The legend only works when passing label to each iteration).
legend_col int The number of columns of the legend, see matplotlib.pyplot.legend to view details. (The legend only works when passing label to each iteration).
fig object A matplotlib figure instance. If not given, would use plt.gcf() for instead.
ax object A matplotlib subplot instance. If not given, would use plt.gca() for instead.

Examples

Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import numpy as np
import matplotlib.pyplot as plt
import mdnc

@mdnc.utils.draw.setFigure(style='ggplot', font_size=14)
def test_plot_hist():
    def func_gen():
        getbins = np.linspace(0, 25, 80)
        x1 = np.random.normal(loc=7.0, scale=1.0, size=100)
        yield x1, {'bins': getbins, 'label': '$x_1$'}
        x2 = np.random.normal(loc=12.0, scale=3.0, size=1000)
        yield x2, {'bins': getbins, 'label': '$x_2$'}

    mdnc.utils.draw.plot_hist(func_gen(), xlabel='x', normalized=True, cumulative=False)
    plt.show()

test_plot_hist()


Last update: March 14, 2021

Comments