Plot Discrete Cumulative Distribution Functions

This python package allows us to plot beautiful cumulative distributions functions and quantile functions for discrete random variables.

PlotCDF Discrete Modules

class discrete.plot.RV(support, prob, is_pmf=True, complete_left=True, complete_right=True, max_tol=1e-12)

We use the class to instantiate a discrete random variable, so we can make beautiful plots for the point mass function (pmf) but more specifically to the cumulative distribution function (cdf) and the quantile (percentile) function.

Parameters
  • support – The part of the support of the discrete random variable that we want to plot, that is, the mass points that we will be using. You should pass any type that can be converted to a numpy array and increasingly ordered.

  • prob – The probability or the cumulative probability for each mass point in the support that we will be using. You should pass any type that can be converted to a numpy array.

  • is_pmf – A boolean stating if in prob you are passing the pmf or the cdf. By default it’s True, so you’ll be passing the pmf.

  • complete_left – A boolean to state if the left tail is complete, that is, if the first mass point in the support is the minimum mass point for this discrete random variable. By default it’s True.

  • complete_right – A boolean to state if the right tail is complete, that is, if the last mass point in the support is the maximum mass point for this discrete random variable. By default it’s True.

  • max_tol – A tolerance value so you can check if the sum of the probabilities are equal to 1 or not. If not, you’ll get a warning. A default float of 1e-12.

static from_cdf_to_pmf(cum_probs)

Converts a cumulative distribution function (cdf) to a point mass function (pmf).

Parameters

cum_probs – The cumulative probabilities, that should be positive, increasing and with a maximum smaller or equal to 1.

Returns

A numpy array with the cdf.

static from_pmf_to_cdf(probs)

Converts a point mass function (pmf) to a cumulative distribution function (cdf).

Parameters

probs – The probabilities, that should be positive and with a sum smaller or equal to 1.

Returns

A numpy array with the pmf.

plot_cdf(rv_name='X', graph_name='', left_points={}, right_points={}, hlines={}, left_line_complete={}, right_line_complete={}, left_line_incomplete={}, right_line_incomplete={}, grid={}, x_y_ticks=10, save=True)

The method used to plot the cumulative distribution function.

Parameters
  • rv_name – The name that will appear in the title.

  • graph_name – the graph’s name used to save the file

  • left_points – A dictionary so you can pass whatever parameters to the left points in the plots.

  • right_points – A dictionary so you can pass whatever parameters to the right points in the plots.

  • hlines – A dictionary so you can pass whatever parameters to horizontal lines in the plots.

  • left_line_complete – A dictionary so you can pass whatever parameters to the left (the first) line in the case the left tail is complete.

  • right_line_complete – A dictionary so you can pass whatever parameters to the right line (the last) in the case the left tail is complete.

  • left_line_incomplete – A dictionary so you can pass whatever parameters to the left (the first) line in the case the left tail is incomplete.

  • right_line_incomplete – A dictionary so you can pass whatever parameters to the right line (the last) in the case the left tail is incomplete.

  • grid – A dictionary so you can pass whatever parameters to the grid’s design.

  • x_y_ticks – The number of axis x and axis y thicks that you want to use. If the number passed is below the supports’s cardinality the default will be used. This is necessary or you’ll end up with a graph to much populated in the axis and difficult to read.

  • save – If you want to save the graph plotted. By default will save an png file, but you can always change it by calling the figure returned (see :return below).

Returns

A tuple with the figure and the plot.

plot_pmf(rv_name='X', graph_name='', points={}, left_line_incomplete={}, right_line_incomplete={}, grid={}, x_y_ticks=10, save=True)

The method used to plot the probability mass function.

Parameters
  • rv_name – The name that will appear in the title.

  • graph_name – the graph’s name used to save the file

  • points – A dictionary so you can pass whatever parameters to the points in the plots.

  • left_line_incomplete – A dictionary so you can pass whatever parameters to the left (the first) line in the case the left tail is incomplete.

  • right_line_incomplete – A dictionary so you can pass whatever parameters to the right line (the last) in the case the left tail is incomplete.

  • grid – A dictionary so you can pass whatever parameters to the grid’s design.

  • x_y_ticks – The number of axis x and axis y thicks that you want to use. If the number passed is below the supports’s cardinality the default will be used. This is necessary or you’ll end up with a graph to much populated in the axis and difficult to read.

  • save – If you want to save the graph plotted. By default will save an png file, but you can always change it by calling the figure returned (see returns below).

Returns

A tuple with the figure and the plot.

plot_quantile(rv_name='X', graph_name='', left_points={}, right_points={}, hlines={}, left_line_complete={}, right_line_complete={}, left_line_incomplete={}, right_line_incomplete={}, grid={}, x_y_ticks=10, save=True)

The method used to plot the percentile (quantile) function.

Parameters
  • rv_name – The name that will appear in the title.

  • graph_name – the graph’s name used to save the file

  • left_points – A dictionary so you can pass whatever parameters to the left points in the plots.

  • right_points – A dictionary so you can pass whatever parameters to the right points in the plots.

  • hlines – A dictionary so you can pass whatever parameters to horizontal lines in the plots.

  • left_line_complete – A dictionary so you can pass whatever parameters to the left (the first) line in the case the left tail is complete.

  • right_line_complete – A dictionary so you can pass whatever parameters to the right line (the last) in the case the left tail is complete.

  • left_line_incomplete – A dictionary so you can pass whatever parameters to the left (the first) line in the case the left tail is incomplete.

  • right_line_incomplete – A dictionary so you can pass whatever parameters to the right line (the last) in the case the left tail is incomplete.

  • grid – A dictionary so you can pass whatever parameters to the grid’s design.

  • x_y_ticks – The number of axis x and axis y thicks that you want to use. If the number passed is below the supports’s cardinality the default will be used. This is necessary or you’ll end up with a graph to much populated in the axis and difficult to read.

  • save – If you want to save the graph plotted. By default will save an png file, but you can always change it by calling the figure returned (see returns below).

Returns

A tuple with the figure and the plot.

Indices and tables