Skip to content

utils.draw.plot_bar

Function ยท Source

mdnc.utils.draw.plot_bar(
    gen, num,
    xlabel=None, ylabel='value', x_tick_labels=None, y_log=False,
    figure_size=(6, 5.5), legend_loc=None, legend_col=None,
    fig=None, ax=None
)

Plot a bar graph for multiple result groups. Each group 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.
num int The total number of data samples yield by the generator.
xlabel str The x axis label.
ylabel str The y axis label.
x_tick_labels (str, ) The x tick labels (a sequence) that is used for overriding the original value [0, 1, 2, ...].
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
18
19
20
import numpy as np
import matplotlib.pyplot as plt
import mdnc

@mdnc.utils.draw.setFigure(style='dark_background', font_size=14)
def test_plot_bar():
    def func_gen():
        size = 5
        x1 = np.abs(np.random.normal(loc=6.0, scale=3.0, size=size))
        yield x1, {'label': '$x_1$'}
        x2 = np.abs(np.random.normal(loc=9.0, scale=6.0, size=size))
        yield x2, {'label': '$x_2$'}
        x3 = np.abs(np.random.normal(loc=12.0, scale=6.0, size=size))
        yield x3, {'label': '$x_3$'}

    mdnc.utils.draw.plot_bar(func_gen(), num=3, ylabel='y', y_log=False,
                             x_tick_labels=['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May'])
    plt.show()

test_plot_bar()


Last update: March 14, 2021

Comments