DotPlot#


class pycafee.normalitycheck.dotplot.DotPlot(language=None, **kwargs)[source]#

Methods

draw(x_exp[, ax, legend_label, x_label, ...])

This function draws a dot plot with a predefined design

get_language()

Returns the current language

set_language(language)

Changes the current language

draw(x_exp, ax=None, legend_label=None, x_label=None, width='auto', height='auto', export=None, file_name=None, extension=None, dpi=None, tight=None, transparent=None, n_ticks=None, legend=None, decimal_separator=None)[source]#

This function draws a dot plot with a predefined design

Parameters
x_exp1D numpy array

A 1 dimension numpy array with the dataset

axNone or matplotlib.axes.SubplotBase
  • 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 dotplot axis. In this case, parameters relatd to wht fig will not affect the graph.

legendbool, optional

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

legend_labelstr, optional

The label to be displayed on the legend. Default is None, which results in "data". Only valid if legend = True.

x_labelstr, optional

The label to be displayed on x label. Default is None, which results in a blank label.

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

The width of the figure.

  • If it is "auto", it tries to figure out a nice width for the plot using the data range.

  • 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"auto", "default", int or float (positive), optional

The height of the figure.

  • If it is "auto", it tries to figure out a nice height for the plot using the data range.

  • 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 "dot_plot".

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 positive number.

n_ticksint (positive), optional

The number of evenly spaced ticks to be drawn on the x-axis. The default is None, which uses matplotlib default parameter.

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 (e.g, white background).

decimal_separatorstr, optional

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

Returns
xnumpy array

The x values used to plot the graph.

ynumpy array

The y values used to plot the graph.

axesmatplotlib.axes._subplots.AxesSubplot

The axis of the graph.

References

1

Inspired by FITZGERALD, P. How to create a “dot plot” in Matplotlib? (not a scatter plot). Available at: stackoverflow.com. Access on: 10 May. 2022.

Examples

Drawing a dot plot with default parameters

>>> from pycafee.normalitycheck.dotplot import DotPlot
>>> import numpy as np
>>> x = np.array([
            5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7,
            5.1, 5.4, 5.1,4.6, 5.1, 4.8, 5.0, 5.0, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5.0, 5.5, 4.9, 4.4,
            5.1, 5.0, 4.5, 4.4, 5.0, 5.1,4.8, 5.1, 4.6, 5.3, 5.0
            ])
>>> dotplot = DotPlot()
>>> x, y, axes = dotplot.draw(x, ax=None, export=True)
    The 'dot_plot.png' file was exported!
Graph showing the dot plot

Drawing a dot plot

>>> from pycafee.normalitycheck.dotplot import DotPlot
>>> import numpy as np
>>> x = np.array([
            5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7,
            5.1, 5.4, 5.1,4.6, 5.1, 4.8, 5.0, 5.0, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5.0, 5.5, 4.9, 4.4,
            5.1, 5.0, 4.5, 4.4, 5.0, 5.1,4.8, 5.1, 4.6, 5.3, 5.0
            ])
>>> dotplot = DotPlot()
>>> x, y, axes = dotplot.draw(x, ax=None, export=True, file_name="my_data", decimal_separator=",", n_ticks=6, x_label='comprimento das sépalas ($cm$)')
    The 'my_data.png' file was exported!
Graph showing the dot plot

Drawing a dot plot using a previously created figure

>>> from pycafee.normalitycheck.dotplot import DotPlot
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x = np.array([
            5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7,
            5.1, 5.4, 5.1,4.6, 5.1, 4.8, 5.0, 5.0, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5.0, 5.5, 4.9, 4.4,
            5.1, 5.0, 4.5, 4.4, 5.0, 5.1,4.8, 5.1, 4.6, 5.3, 5.0
            ])
>>> dotplot = DotPlot()
>>> fig, ax = plt.subplots(figsize=(8,4))
>>> x, y, ax = dotplot.draw(x, ax=ax)
>>> plt.savefig("new_plot.png")
>>> plt.show()
Graph showing the dot plot
get_language()#

Returns the current language

set_language(language)#

Changes the current language

Parameters
languagestr

The language code

Notes

The language must be a str with no more then 5 elements.