draw#

pycafee.sample.studentdistribution.StudentDistribution.draw(self, gl, tcalc, alfa=None, ax=None, which=None, interval=None, legend=None, x_label=None, y_label=None, width='default', height='default', export=None, file_name=None, extension=None, dpi=None, tight=None, transparent=None, plot_design='gray', decimal_separator=None)#

This function draws a graph with the Student’s t distribution (one-sided or two-sided) for a given degree of freedom, combined with the calculated value of the statistic of this test for a sample with an alpha level of significance.

Parameters
glint, higher than 1

The degree of freedom of the sample

tcalcfloat or int

The calculated value of the Student’s t-test statistic

alfafloat

The level of significance, 0.0 < alfa < 1.0.

axNone or matplotlib.axes.SubplotBase, optional
  • If ax is None, a figure is created with a preset design. The other parameters can be used to edit and export the graph.

  • If ax is a matplotlib.axes.SubplotBase, the function returns a matplotlib.axes.SubplotBase with the StudentDistribution axis. In this case, the parameters related to graph export will not influence the generated axis.

whichstr, optional

The parameter which controls the t distribution to be ploted. The options are:

  • None or "two-side" (default): two-side

  • "one-side": one-side

intervalNone or list, optional

The interval

  • If it is None, it tries to find a suitable range to plot the graph.

  • If it is a list, the list must contain 2 positive numeric elements, where the first element defines the lower limit of the interval, and the second element defines the upper limit of the interval.

legendbool, optional

Whether the legend should be added into the chart (True) or not (False). The default value is None, which implies True.

x_labelstr, optional

The label to be displayed on x label. Default is None, which results in "Student's t".

y_labelstr, optional

The label to be displayed on y label. Default is None, which results in "Probability density".

width"default", int or float (positive), optional

The width of the figure. If it is "default", it uses a pre-defined value. If it is a number, it defines the width of the chart (in inches).

height"default", int or float (positive), optional

The height of the figure. If it is "default", it uses a pre-defined value. If it is a number, it defines the height of the chart (in inches).

exportbool, optional

Whether the graph should be exported (True) or not (False). The default value is None, which implies False.

file_namestr, optional

The file name. Default is None which results in a file named "student_distribution".

extensionstr, optional

The file extension without a dot. Default is None which results in a ".png" file.

dpiint or float (positive), optional

The figure pixel density. The default is None, which results in a 100 dpis picture. This parameter must be a number higher than zero.

tightbool, optional

Whether the graph should be tight (True) or not (False). The default value is None, which implies True.

transparentbool, optional

Whether the background of the graph should be transparent (True) or not (False). The default value is None, which implies False (white).

plot_designstr or dict, optional

The plot desing. If "gray", uses a gray-scale desing (default). If "colored", uses a colored desing. If dict, it must have four keys ("distribution", "area-rejection", "area-acceptance", "tcalc"), where each one defines the design of each element added to the chart.

decimal_separatorstr, optional

The decimal separator symbol used in the chart. It can be the dot (None or '.') or the comma (',').

Returns
axesmatplotlib.axes._subplots.AxesSubplot

The axis of the graph.

outputdict

A dictionary with the data used to plot the graph.

  • If which = "two-side"

  • If which = "one-side"

Notes

The plot_design parameter must be a dict where the values for all keys must be a list. The list of the key "distribution" must have:

  • the first element must be a str with the color name;

  • the second element must be a str with line style;

  • the third element must be a number (int or float, positive) with the line thickness;

The list of the key "tcalc" must have:

  • the first element must be a str with the color name;

  • the second element must be a str with the marker;

  • the third element must be a number (int or float, positive) with size of the marker;

The area-rejection and area-acceptance lists must have a single element, which is a str with the name of the color that fills the area between the distribution line and the line y = 0. For example:

plot_design = {
    "distribution": ['k', '-', 1.5],
    "area-rejection": ['gainsboro'],
    "area-acceptance": ['white'],
    "tcalc": ['k', 'o', 50],
}

A list of color names can be found at matplotlib’s documentation.

A list of linestyles can be found here.

A list of makers can be found on this link.

The critical values for the sample are obtained using the scipy percent point function [1]:

stats.t.ppf(1-alfa/2, gl) or stats.t.ppf(alfa/2, gl) # for the two-side distribution
stats.t.ppf(1-alfa, gl) or stats.t.ppf(alfa, gl) # for the one-side distribution

The density values are estimated using the scipy probability density function [1]:

stats.t.pdf(x,gl)

References

1(1,2)

SCIPY. scipy.stats.t. Available at: www.scipy.org. Access on: 10 May. 2022.

Examples

>>> from pycafee.sample.studentdistribution import StudentDistribution
>>> student = StudentDistribution()
>>> axes, output = student.draw(gl=4,tcalc=3.15, export=True)
    The 'student_distribution.png' file was exported!
Graph showing the student's plot
>>> from pycafee.sample.studentdistribution import StudentDistribution
>>> student = StudentDistribution()
>>> axes, output = student.draw(gl=4,tcalc=-3.15, export=True, plot_design='colored', file_name='my_data')
    The 'my_data.png' file was exported!
Graph showing the student's plot
>>> from pycafee.sample.studentdistribution import StudentDistribution
>>> student = StudentDistribution(language='pt-br')
>>> axes, output = student.draw(gl=4,tcalc=1.15, which='one-side', export=True, plot_design='colored', file_name='meus_dados')
    O arquivo 'meus_dados.png' foi exportado!
Graph showing the student's plot